Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在ng repeat筛选器中使用范围变量?_Javascript_Html_Angularjs - Fatal编程技术网

Javascript 如何在ng repeat筛选器中使用范围变量?

Javascript 如何在ng repeat筛选器中使用范围变量?,javascript,html,angularjs,Javascript,Html,Angularjs,我完全确定我的做法是错误的,但是看到我对angularjs有多新,我不知道如何实现我想要的。我使用ng repeat浏览了一组用户,但我不知道如何通过范围变量userId进行过滤。用户id:打印得很好,因此范围没有问题。如何让ng repeat循环按此userId排序?如果我做错了什么,你能帮我把文档链接起来,帮助我以正确的方式进行吗 HTML: 如果用户的结构如下所示: [ {id:1,name:'xxx'}, {id:2,name:'yyy'} ] 您可以使用“orderB

我完全确定我的做法是错误的,但是看到我对angularjs有多新,我不知道如何实现我想要的。我使用
ng repeat
浏览了一组用户,但我不知道如何通过范围变量
userId
进行过滤。
用户id:
打印得很好,因此范围没有问题。如何让
ng repeat
循环按此
userId
排序?如果我做错了什么,你能帮我把文档链接起来,帮助我以正确的方式进行吗

HTML:


如果
用户的结构如下所示:

[
    {id:1,name:'xxx'},
    {id:2,name:'yyy'}
]
您可以使用“orderBy”过滤器对其进行排序,并使用
filter
filter对其进行过滤:

<ul>
    <li ng-repeat="user in users | filter:{id:userId} | orderBy: 'id' ">
        {{user.name}}
    </li>
</ul>
  • {{user.name}
id
ng repeat
user
的属性


以下是文档:

您可以简单地在ng中使用
$scope
变量
userId
,这样重复

<ul>
    <li ng-repeat="user in users | filter:userId">
        {{user.name}}
    </li>
</ul>
  • {{user.name}
基本上不需要角度表达式,因为它已经在表达式中了

如果你需要的话,有几个链接可以帮助你

在决定是否使用卷发时


我可以问一下,
$scope.users
声明在哪里吗?对不起,我漏掉了。它来自一个NGR资源。很有效,谢谢。这正是我不明白的。工作完美。为了帮助您理解,更新了两个好链接的答案。非常感谢!
<ul>
    <li ng-repeat="user in users | filter:{id:userId} | orderBy: 'id' ">
        {{user.name}}
    </li>
</ul>
<ul>
    <li ng-repeat="user in users | filter:userId">
        {{user.name}}
    </li>
</ul>