简体   繁体   English

对象中的AngularJS ng-repeat ng-show数组

[英]AngularJS ng-repeat ng-show array in object

I have array of array which needs to be able to be sorted and put in order 我有一个数组数组,需要能够按顺序排序和排序

my problem is sorting objects by order and array that contains info which both is within the array, my approach was to use 我的问题是按顺序排序对象,数组包含两个都在数组内的信息,我的方法是使用

<a ng-repeat="s in stops | orderBy:'+train_routes[0].stop_seq'"
ng-show="s.train_routes[0].route_id.indexOf('5') > -1">

because I have a lot of data and I don't want to organize it as it will become a much larger and crash 因为我有很多数据而且我不想组织它,因为它会变得更大并且崩溃

I know the problem is [0] , but I don't know any other way 我知道问题是[0] ,但我不知道其他任何方式

I want it to show the object that has the array containing info 我希望它显示包含信息的数组的对象

This works 这有效

    ng-show="s.train_routes[0].route_id.indexOf('6') > -1"

this doesn't work 这不起作用

    ng-show="s.train_routes[0].route_id.indexOf('5') > -1">

http://plnkr.co/edit/MbjKKtTbs3EgO6a4WCRL?p=preview http://plnkr.co/edit/MbjKKtTbs3EgO6a4WCRL?p=preview

EDITED Let's say the user wants to see specific train route, it must show all the stops on that train line, and show the other available trains linked to the requested by the user. 编辑假设用户想要查看特定列车路线,它必须显示该列车线路上的所有站点,并显示链接到用户请求的其他可用列车。

 ng-show="train_routes[0].IndexOf('requestedroute')"

will only show if the 0 index matches the requested route. 仅显示0索引是否与请求的路由匹配。

I will like it to show all the values in every index if the array contains the requested route 如果数组包含请求的路由,我希望它显示每个索引中的所有值

You can use Angular filters , so that you do not append useless elements in the DOM. 您可以使用Angular 过滤器 ,这样就不会在DOM中附加无用的元素。

In the view: 在视图中:

<a ng-repeat="s in stops | filter: avoid5 | orderBy:'+train_routes[0].stop_seq'">

In the controller: 在控制器中:

$scope.avoid5 = function(value, index, array){
   return value.train_routes[0].route_id.indexOf('5') > -1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM