gpt4 book ai didi

javascript - 在 Angular js中过滤(键,值)数组

转载 作者:行者123 更新时间:2023-12-03 04:15:21 24 4
gpt4 key购买 nike

我正在 Angular 1.x 中编写一段代码,我想在其中过滤键、值的数组。

HTML:

<input type="text" ng-model="cust"> 

<div ng-repeat="customer in customers| filter :cust['name']">
{{customer["name"]}}
</div>

JS:

$scope.customers = [
{"name":"Sathish"},
{"name":"Ankur"},
{"name":"Bob"},
{"name":"Mike"},
{"name":"chris"},
{"name":"chrom"}
];

Basically I want to filter the array based on name of customer. if I give "ch" in the input text box it should give filter and give chris and chrom.

最佳答案

您想根据 cust 名称进行过滤,但 cust 只是一个字符串,因此不确定您当前正在做什么。正确的方法是:

<div ng-repeat="customer in customers| filter :{name : cust}">

关于javascript - 在 Angular js中过滤(键,值)数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44163992/

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