【问题标题】:Filter with nested element and scope AngularJS使用嵌套元素和范围 AngularJS 过滤
【发布时间】:2015-02-04 07:51:08
【问题描述】:

不太清楚我在这里做错了什么。我正在尝试返回用户名等于当前用户的对话的参与者。这些是视图中的范围:

conversation: [{id: 1, 
                participants: [{
                  date: 1234, 
                  user: [{
                      username: "test001", 
                      id: 2}],
                  },
                  {
                  date: 1456, 
                  user: [{
                      username: "test005", 
                      id: 5}],
                  }]
                }]
 user: [{username: "test001",
         id: 2}]

当调用 {{user.username}} 时它可以工作(不用担心加载范围) 这是带有过滤器的html中的代码:

        <div class="list">
            <a ng-repeat="conversation in conversations"> 
                <div ng-repeat="notMe in conversation.participants | filter:{user: [{ username: user.username }] }">

                  {{notMe}}

                </div>
            </a>
        </div>

我想避免构建一个特定的过滤器,并认为有角度的过滤器应该可以处理这个问题吗? 感谢您的帮助:-)

【问题讨论】:

  • 暂时结束了使用 ng-if 但如果能理解我的过滤器的问题会很棒:)

标签: javascript arrays angularjs filter


【解决方案1】:
<div ng-repeat="notMe in conversation.participants | filter:{user: { username: user.username } }">

删除了 [ ] 并且它可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    相关资源
    最近更新 更多