使用angularjs完成增删单元格需求

博客围绕规格选项编辑窗口展开,需求是点击“新增规格选项”后下方出现带删除按钮的 input 行,点击可删除。还介绍了点击事件中“entity={specificationOptionList:[]}”的思路,即把 specificationOptionList 对象存到 entity 中并初始化,后端可将其包装为新实体类。

需求:此为编辑窗口,要求点击“新增规格选项后”,下方出现一行input,input中有删除按钮,点击可删除

此为规格编辑按钮:
新建

点击事件中"entity={specificationOptionList:[]}"的思路:
因为要传多个对象到后台,所以将specificationOptionList对象存到entity对象中并初始化俩个对象

此为增删规格选项窗口

新增规格选项
         </div>
		 
		 <table class="table table-bordered table-striped table-hover dataTable">
                <thead>
                    <tr>
                      
				 
			      <th class="sorting">规格选项</th>
			      <th class="sorting">排序</th>																
                  <th class="sorting">操作</th>	
                </thead>
                <tbody>
                  <tr ng-repeat="pojo in entity.specificationOptionList">
                       
			            <td>
			            	<input  class="form-control" placeholder="规格选项" ng-model="pojo.optionName"> 
			            </td>
			            <td>
			            	<input  class="form-control" placeholder="排序" ng-model="pojo.orders"> 
			            </td>
						<td>
							<button type="button" class="btn btn-default" title="删除" ng-click="deleTableRow($index)" ><i class="fa fa-trash-o"></i> 删除</button>
						</td>
                  </tr>
				 
                </tbody>
		  </table> 

js:

//增加规格选项行
$scope.addTableRow=function(){
	$scope.entity.specificationOptionList.push({});			
}
entity.specificationOptionList中元素用ng-model完成双向绑定并遍历元素,push方法存入集合元素


//删除规格选项行
$scope.deleTableRow=function(index){
	$scope.entity.specificationOptionList.splice(index,1);
	//用splice方法删除当前索引的集合元素
}
删除主要是找到当前input在集合中索引,用$index获取当前索引

而后端可以将其包装为新的由俩个对象组成的实体类

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值