//新增扩展属性行
$scope.addTableRow=function(){
$scope.entity.customAttributeItems.push({});
}
<button type="button" class="btn btn-default" title="新建" data-toggle="modal"
data-target="#editModal" ng-click="entity={customAttributeItems:[]}"><i class="fa
fa-file-o"></i> 新建</button>
<button type="button" class="btn btn-default" title="新增扩展属性"
ng-click="addTableRow()"><i class="fa fa-file-o"></i> 新增扩展属性</button>
<tr ng-repeat="pojo in entity.customAttributeItems">
<td><input class="form-control" ng-model="pojo.text" placeholder="属性名称" ></td>
<td><button type="button" class="btn btn-default" title="删除"><i class="fa
fa-trash-o"></i> 删除</button> </td>
</tr>
//删除扩展属性行
$scope.deleTableRow=function(index){
$scope.entity.customAttributeItems.splice(index,1);//删除
}
<button type="button" ng-click="deleTableRow($index)" class="btn btn-default" title="
删除"><i class="fa fa-trash-o"></i> 删除</button>
<tr>
<td>模板名称</td>
<td><input ng-model="entity.name" class="form-control"
placeholder="模板名称"> </td>
</tr>
<button class="btn btn-success" data-dismiss="modal" aria-hidden="true"
ng-click="save()">保存</button>
//查询实体
$scope.findOne=function(id){
typeTemplateService.findOne(id).success(
function(response){
$scope.entity= response;
$scope.entity.brandIds= JSON.parse($scope.entity.brandIds);//转换
品牌列表
$scope.entity.specIds= JSON.parse($scope.entity.specIds);//转换规
格列表
$scope.entity.customAttributeItems=
JSON.parse($scope.entity.customAttributeItems);//转换扩展属性
}
);
}
//提取 json 字符串数据中某个属性,返回拼接字符串 逗号分隔
$scope.jsonToString=function(jsonString,key){
var json=JSON.parse(jsonString);//将 json 字符串转换为 json 对象
var value="";
for(var i=0;i<json.length;i++){
if(i>0){
value+=","
}
value+=json[key];
}
return value;
}
<tr ng-repeat="entity in list">
<td><input type="checkbox" ng-click="updateSelection($event,entity.id)"></td>
<td>{{entity.id}}</td>
<td>{{entity.name}}</td>
<td>{{jsonToString(entity.brandIds,'text')}}</td>
<td>{{jsonToString(entity.specIds,'text')}}</td>
<td>{{jsonToString(entity.customAttributeItems,'text')}}</td>
<td class="text-center">
<button type="button" class="btn bg-olive btn-xs" data-toggle="modal"
data-target="#editModal" ng-click="findOne(entity.id)">修改</button>
</td>
</tr>
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |