更新的
我的问题是如何通过提供数组索引data-ng-repeat="scenarios in input.model.Scenarios[1]"来循环特定的数组,而不是循环所有数组data-ng-repeat="scenarios in input.model.Scenarios"?
例如:
假设我有这样的数组
Scenario[0]
SceId
SceName
Sections[0]
LicencePlates[0]
LpId
LpName
LicencePlates[0]
LpId
LpName
Scenario[1]
SceId
SceName
Sections[0]
LicencePlates[0]
LpId
LpName
LicencePlates[0]
LpId
LpName
Scenario[2]
SceId
SceName
Sections[0]
LicencePlates[0]
LpId
LpName
LicencePlates[0]
LpId
LpName角码
<div data-ng-app="cpa" data-ng-controller="InputController as input">
<div data-ng-repeat="scenarios in input.model.Scenarios">
<div data-ng-repeat="sections in scenarios.Sections">
<div data-ng-repeat="licensePlates in sections.LicensePlates">
</div>
</div>
</div>
</div>对于上面的内容,我将遍历所有数组并获得结果。
<div data-ng-app="cpa" data-ng-controller="InputController as input">
<div data-ng-repeat="scenarios in input.model.Scenarios[1]">
<div data-ng-repeat="sections in scenarios.Sections">
<div data-ng-repeat="licensePlates in sections.LicensePlates">
</div>
</div>
</div>
</div>但是对于上面的代码,当我使用Scenarios[1]时,它是循环Scenarios1,而不是进入Sections[0]和LicencePlates[0]。
输出:
SceId : 2
SceName : Scenario2在实时中,我将父$index作为数组索引传递
<div data-ng-repeat="scenarios in input.model.ParentScenarios" ng-init="ParentScenarioIndex = $index">
<div data-ng-repeat="scenarios in input.model.Scenarios[ParentScenarioIndex]">
发布于 2015-09-12 11:00:24
第二种情况下的问题是,您希望使用ng-重复循环对象。
data-ng-repeat="scenarios in input.model.Scenarios[1]"在本例中,input.model.Scenarios[https://docs.angularjs.org/api/ng/directive/ngRepeat]是一个对象,ng重复将循环遍历它的属性值。示例:
// for
var object = { a: 'aa', foo: 'bar' };
// and
data-ng-repeat="value in object"
// value will receive 'aa' and 'bar'如果只想显示第一个对象的数据,可以这样做:
<div data-ng-app="cpa" data-ng-controller="InputController as input">
<div data-ng-init="scenario = input.model.Scenarios[1]">
<div data-ng-repeat="sections in scenario.Sections">
<div data-ng-repeat="licensePlates in sections.LicensePlates">
</div>
</div>
</div>
</div>我希望这个答案能对你有所帮助。关于更多的信息,你可以检查角文档的ng-重复或给我写一个评论。
https://stackoverflow.com/questions/32535234
复制相似问题