gpt4 book ai didi

javascript - 输入字段过滤器在 AngularJS 中不起作用

转载 作者:行者123 更新时间:2023-11-30 16:26:59 26 4
gpt4 key购买 nike

我在 this fiddle 中成功实现了几乎所有类型的过滤器:

<div data-ng-app='' data-ng-init="vehicles=[
{type:'car',color:'red'},
{type:'bike',color:'black'}]">
<h1>
AngularJS <a href='http://www.w3schools.com/angular/angular_filters.asp'>
Filters Example</a>
</h1>

<p>Enter text
<input type='text' data-ng-model='abc' />
</p>
<p>The text you entered is
<br/> <a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_uppercase'>Upper case</a> {{ abc | uppercase }}
<br/><a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_lowercase'>Lower case</a> {{ abc | lowercase }}</p>Enter amount
<input type='number' data-ng-model='num1' />
<p>The <a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_currency'>amount</a> you entered is
<br/>{{ num1 | currency }}</p> <a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_orderby'> Directives Filter example</a>

<br/>Vehicles filtered by type:
<ul data-ng-repeat="v in vehicles | orderBy:'type'">
<li>{{"Vehicle type is "+v.type +" with color "+ v.color}}</li>
</ul>
<br/>Vehicles <a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_filters_input'>filtered by user input:</a>

<br/>
<input type="text" ng-model='test' />
<ul data-ng-repeat="v in vehicles | filter: 'test' | orderBy:'type'">
<li>{{"Vehicle type is "+v.type +" with color "+ v.color}}</li>
</ul>
</div>

一切正常,除了 input filters .

我就是这样seeing现在:

no output

Why is the array not printed and filtered by user input?

最佳答案

从传递给过滤器的 'test' 中删除单引号。由于它不是字符串,它是一个模型,应该直接传递给过滤器。

<ul data-ng-repeat="v in vehicles | filter: test | orderBy:'type'">
<li>{{"Vehicle type is "+v.type +" with color "+ v.color}}</li>
</ul>

上面的代码可以工作。

关于javascript - 输入字段过滤器在 AngularJS 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33981759/

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