Home  >  Article  >  Web Front-end  >  s:iterator动态显示输入框问题_html/css_WEB-ITnose

s:iterator动态显示输入框问题_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:44:131138browse

jsp代码和页面如下

  <body ><br>     <div  align="center">          <a href="listAllDataInfo">显示所有</a>	<table width="500" border="1" class="table">		<tbody align="center">		    <tr>		    <td colspan="5" style="font-size: 20;">指标信息</td>		    <tr>			   <td width="105">指标编码</td>               <td width="300">指标名称</td>               <td>填写数值</td> 			</tr>			<!--循环显示记录部分  -->		<s:iterator value="list" >            <tr class="br_TR">                    <td><s:property value="indexCode"/></td>  				<td><s:property value="indexName"/></td>                         <td><input name="" /></td>        </s:iterator> 				</tbody>	</table>  	</div>  </body>




我先将数据库Index表里的每条记录都通过s:iterator显示,然后每条记录后面加上了文本框。
问题来了,我想对每个文本框输入值,然后把所有的值都储存在数据库对象里,每个值对应一条记录。这种动态显示的存值要如何实现?


回复讨论(解决方案)

迭代的时候顺便给每个INPUT元素加上ID,然后加个按钮,点击之后获取所有INPUT的value,发送给后端保存。

迭代的时候顺便给每个INPUT元素加上ID,然后加个按钮,点击之后获取所有INPUT的value,发送给后端保存。



那jsp页面的input里面的id元素怎么写呢? 每行input的id应该不同吧?id里应该是要填一个什么变量吧?可否按照我给的举例?


迭代的时候顺便给每个INPUT元素加上ID,然后加个按钮,点击之后获取所有INPUT的value,发送给后端保存。



那jsp页面的input里面的id元素怎么写呢? 每行input的id应该不同吧?id里应该是要填一个什么变量吧?可否按照我给的举例?

<body ><br>     <div  align="center">          <a href="listAllDataInfo">显示所有</a>    <table width="500" border="1" class="table">        <tbody align="center">            <tr>            <td colspan="5" style="font-size: 20;">指标信息</td>            <tr>               <td width="105">指标编码</td>               <td width="300">指标名称</td>               <td>填写数值</td>             </tr>            <!--循环显示记录部分  -->        <s:iterator value="list" >            <tr class="br_TR">                    <td><s:property value="indexCode"/></td>                  <td><s:property value="indexName"/></td>                         <td><input id="<s:property value="indexCode"/>" /></td>        </s:iterator>                </tbody>    </table>      </div>  </body>

迭代的时候顺便给每个INPUT元素加上ID,然后加个按钮,点击之后获取所有INPUT的value,发送给后端保存。


感谢你的耐心,
    "
用到了list自身的属性,但我是要把这6条记录存在另一个数据库表,不是list表里,该怎么弄呢?
s:iterator标签貌似只能对一个list遍历操作吧?

我有点不懂你的需求了,你不是要把input里的数值存到数据库去么?存到哪里完全看你后端如何运行啊,JS又不会存储数据库,只能发请求到后端进行处理。

我有点不懂你的需求了,你不是要把input里的数值存到数据库去么?存到哪里完全看你后端如何运行啊,JS又不会存储数据库,只能发请求到后端进行处理。

 
不好意思,需求之前没说清楚。
有三个表,Index表和data表和user表。每个user数据对应不定量条的data数据。
index表就包含指标名称和指标编码(如图所示),只存放数据的一些基本信息比如名称,不存放具体的数据。
data表才是专门存数据的。如图总共有6条指标,那么我填满6个text,存入data表里的记录就有6条了,假如我只填写4条text,剩下2条不填写空在那里,点提交后,存入data表里的记录就只有4条。
为了实现这样的需求,我要怎么做呢?

 

	<s:form action="updateAllDataInfo" method="post">	<table width="500" border="1" class="table">		<tbody align="center">		    <tr>		    <td colspan="5" style="font-size: 20;">指标信息</td>		    </tr>		    <tr>			   <td width="105">指标编码</td>               <td width="300">指标名称</td>               <td>填写数值</td> 			</tr>			<!--循环显示记录部分  -->		    <s:iterator value="list" status="status" >            <tr >                <td><s:property value="indexCode"/></td>  				<td><s:property value="indexName"/></td>                        <td><input type="text" name="dataInfoList[#status.index].indexValue" style="width:100"/></td>              </tr>                </s:iterator>             <s:submit value="保存" align="center" /> 

不知道我楼上的方法怎么样?但dataInfoList[#status.index].indexValue值传不到action里
public String updateAll() throws Exception{		System.out.println("开始");	//	List<IndexInfo> list = (List<IndexInfo>)session.get("list");	  		for(int i = 0; i < dataInfoList.size(); i++)          {   			dataInfoBiz.addDataInfo(dataInfoList.get(i));                       }  		return this.listAll();	}


private List dataInfoList;是有getset方法的

建议你最好前后端都调试一下,看看前端发送的数据格式是怎样的,然后后端再根据格式获取数据。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn