gpt4 book ai didi

javascript - 无法从自定义 AngularJS 过滤器更新 Controller 的范围级别属性

转载 作者:行者123 更新时间:2023-11-28 00:28:38 25 4
gpt4 key购买 nike

我想在 UI 中显示表中存在的记录数。但我无法更新过滤器内 Controller 范围内存在的记录属性。请帮助我。

<p>{{records}}</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Customer Account</th>
<th>Storage</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="customer in (customerList | filterGridData:records)">
<td>{{customer.display_name}}</td>
<td>{{customer.storageStatus || "loading..."}}</td>
<td>{{customer.state}}</td>
</tr>
</tbody>
</table>

Controller -

$http.get(list.json).then(function(response){
$scope.customerList = data;
$scope.records = $scope.customerList.length; //use for displaying no of records in the table
});

过滤器 -

 filterGridData(records) {
// some filter logic on the customerList data and then the filtered data will
// be displayed in the table and also the updated no of records should be displayed
records = filterData.length;
}

最佳答案

您将无法更改过滤器中传递的记录值,因为这是原始值,并且原始类型是按值传递的。相反,你应该这样做:

<p>{{filtered.length}}</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Customer Account</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="customer in filtered = (customerList | filterGridData)">
<td>{{customer.display_name}}</td>>
</tr>
</tbody>
</table>

Controller 和过滤器中不再需要 $scope.records

关于javascript - 无法从自定义 AngularJS 过滤器更新 Controller 的范围级别属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29226761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com