基于json值的Angularjs ng-repeat过滤器

ttm*_*tmt 1 angularjs angularjs-ng-repeat angularjs-filter

我这里有一个玩家 - http://plnkr.co/edit/AmoiJi8k000OKA6TNdcz?p=preview

我在这里使用虚拟json - http://myjson.com/4aqlh

我想根据json中的值在页面的不同部分显示json内容

所以具有Section:"New"值的故事将显示在一个div中,而"Old"显示在另一个div中.

这适用于第一个div,其中'New'是显示的,但是在第二个div中只显示'Old',它显示所有的故事.

过滤器有什么问题,或者与Angular构建页面的顺序有关.

        <div class="container" data-ng-controller="myCtrl">

            <div class="row">

                <div  class="col-sm-6">
                    <div class="story" data-ng-repeat="story in stories | filter: story.Section='New' " >
                        {{story.Title}}
                        {{story.Section}}
                    </div>
                </div>

                <div  class="col-sm-6">
                    <div class="story" data-ng-repeat="story in stories | filter: story.Section='Old' ">
                        {{story.Title}}
                        {{story.Section}}
                    </div>
                </div>

            </div>

        </div>
Run Code Online (Sandbox Code Playgroud)

Cha*_*ani 6

这是你用过滤的方法 filter

            <div  class="col-sm-6">
                <div class="story" data-ng-repeat="story in stories | filter: {Section:'New'}" >
                    {{story.Title}}
                    {{story.Section}}
                </div>
            </div>

            <div  class="col-sm-6">
                <div class="story" data-ng-repeat="story in stories | filter: {Section:'Old'}">
                    {{story.Title}}
                    {{story.Section}}
                </div>
            </div>
Run Code Online (Sandbox Code Playgroud)

它采用对象语法.=是一个赋值运算符.请参阅过滤器文档