AngularJS NG重复NG-显示数组对象 [英] AngularJS ng-repeat ng-show array in object

查看:145
本文介绍了AngularJS NG重复NG-显示数组对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有阵列的阵列,其需要能够进行排序,并把为了

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

我知道问题出在 [0] ,但我不知道任何其他方式

I know the problem is [0], but I don't know any other way

我希望它表明,具有包含信息的数组对象

I want it to show the object that has the array containing info

这工作

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

这不起作用

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

http://plnkr.co/edit/MbjKKtTbs3EgO6a4WCRL?p=$p$ PVIEW

EDITED
比方说,用户希望看到具体的火车路线,它必须显示在该铁路线全部停止,并显示链接到用户请求其他可用的列车。

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')"

如果0指数请求路由匹配才会显示。

will only show if the 0 index matches the requested route.

我会喜欢它显示在各项指标中的所有值,如果数组包含所请求的路线

I will like it to show all the values in every index if the array contains the requested route

推荐答案

您可以使用角过滤器,这样就不会附加在DOM元素没用

You can use Angular filters, so that you do not append useless elements in the DOM.

在该视图:

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

在控制器:

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

这篇关于AngularJS NG重复NG-显示数组对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆