gpt4 book ai didi

AngularJS - 用数字/长度过滤复选框

转载 作者:行者123 更新时间:2023-12-03 08:22:13 26 4
gpt4 key购买 nike

我有一个应用程序可以搜索各种门票。
在侧边栏中,我有一些过滤器,因此用户可以过滤他们的结果(包括复选框和单选按钮,如 eBay/Amazon 等)。

所以它在侧边栏中看起来类似于:

如何购买

直接借记 (10)
现金 (2)

所以用户一看就知道,如果他们点击 Direct Debit,它将返回 10 个结果。然后我遇到的问题是,当用户单击“直接借记”时,单选按钮更改为...

如何购买

直接借记 (10)
现金 (0)

如果它是一个复选框,这将是正确的,因为单击 Direct Debit AND Cash 将返回 0 结果。然而,在这种情况下(一个单选按钮),如果用户点击 Cash,他们仍然应该看到有 2 个结果。

这是我的代码...

HTML

<ul class="checkbox-list nga-fast nga-collapse" data-ng-show="ticketing.filterButtons.OperatorBtn">
<li data-ng-repeat="filter in ticketing.filterButtons.Operator | orderBy: filter" data-ng-if="filter != null">
<input id="operator{{$index}}" name="operator{{$index}}" type="radio" class="stylized" data-ng-model="ticketing.searchFilters.Operator" data-ng-change="ticketing.update()" value="{{filter}}" />
<label for="operator{{$index}}">{{filter}}
({{ (ticketing.filteredTickets | filter: {Operator: filter}).length}})
</label>
</li>
</ul>

JS
function update() {
var filtered = vm.all;
console.log(vm.searchFilters);
// For each filter in the search filters loop through and delete any that state false, this is so it doesn't explicitly match false and shows everything.
angular.forEach(vm.searchFilters, function(val, key) {
// if Key/Property contains 'Allow" and the value is true || if Key/Property doesn't contain 'Allow' and val is false (this is to make sure the oppposite/exclude filter values are deleted as the trues will be falses and vice versa)
if ((key.indexOf('Allow') !== -1 && val) || (val == false && key.indexOf('Allow') === -1)) {
// Delete the filter and value
delete vm.searchFilters[key];
}
});

// Filter results by the filters selected
filtered = $filter('filter')(filtered, vm.searchFilters);

// Sort results by selected option
vm.filteredTickets = $filter('orderBy')(filtered, vm.orderBy);

console.log(vm.filteredTickets);
console.log(vm.searchFilters);

vm.updateGrid();
}

如果您需要更多信息或代码,请告诉我,我会提供。

最佳答案

这是一个猜测。以下行中可能有问题

     ({{ (ticketing.filteredTickets | filter: { Operator:filter}).length}})           

点击 Direct Debit";您可能仅使用“直接借记”数据更新了“ticketing.filteredTickets”,因此没有“现金”数据

关于AngularJS - 用数字/长度过滤复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51323711/

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