我目前正在使用AngularJS,这是我的HTML:
<tbody>
<tr dir-paginate="tdata in tableData | orderBy:predicate:reverse | filter:searchFilter | itemsPerPage:10 track by $index ">
<td class="table-data-edit-all">
<input type="checkbox" ng-model="tdata.selectedCell">
</td>
<td class="align-left">
{{ tdata.companyName }}
</td>
<td class="align-left">
{{ tdata.department }}
</td>
<td>
<a ng-click="editCompany({{ tdata.id }})"><i class="fa fa-edit"></i></a>
<a ng-click="removeCompany({{ tdata.id }})"><i class="fa fa-remove"></i></a>
</td>
</tr>
</tbody>
这是Angular:
$scope.editCompany = function(index) {
console.log(index);
// my stuffs
}
加载页面时:
tdata.id
在HTML视图中显示数字标识1
editCompany(index)
也会打印到控制台号码1
。 sort
后,
tdata.id
显示与之对应的号码10
tdata.companyName
。但是,此时editCompany(index)
仍然存在
打印到控制台号码1
,而不是10
。 我该如何解决?
答案 0 :(得分:1)
使用ng-click="editCompany(tdata.id)
代替ng-click="editCompany({{tdata.id}})
<tbody>
<tr dir-paginate="tdata in tableData | orderBy:predicate:reverse | filter:searchFilter | itemsPerPage:10 track by $index ">
<td class="table-data-edit-all">
<input type="checkbox" ng-model="tdata.selectedCell">
</td>
<td class="align-left">
{{ tdata.companyName }}
</td>
<td class="align-left">
{{ tdata.department }}
</td>
<td>
<a ng-click="editCompany(tdata.id)"><i class="fa fa-edit"></i></a>
<a ng-click="removeCompany(tdata.id)"><i class="fa fa-remove"></i></a>
</td>
</tr>
</tbody>
答案 1 :(得分:0)
哟必须从代码中删除{{}}
在HTML中
<tbody>
<tr dir-paginate="tdata in tableData | orderBy:predicate:reverse | filter:searchFilter | itemsPerPage:10 track by $index ">
<td class="table-data-edit-all">
<input type="checkbox" ng-model="tdata.selectedCell">
</td>
<td class="align-left">
{{ tdata.companyName }}
</td>
<td class="align-left">
{{ tdata.department }}
</td>
<td>
<a ng-click="editCompany(tdata.id)"><i class="fa fa-edit"></i></a>
<a ng-click="removeCompany(tdata.id)"><i class="fa fa-remove"></i></a>
</td>
</tr>
我希望这能帮到你