简体   繁体   English

如何对两个模型进行ng-repeat

[英]How to ng-repeat over two models

I am very new to Angular, and am looking for a clean solution for an issue: 我是Angular的新手,正在寻找一个干净的解决方案:

I have a element called "SelectedList" that has two show a list of elements that have been made 'active' in another container. 我有一个名为“ SelectedList”的元素,该元素有两个显示在另一个容器中已被“激活”的元素的列表。 Now this container has two tabs Tab1 and Tab2, populated from $scope.model1 and $scope.model2. 现在,此容器具有两个选项卡Tab1和Tab2,分别从$ scope.model1和$ scope.model2填充。 Now if an element Element1 in Tab1 is selected, I need to add it to "SelectedList". 现在,如果在Tab1中选择了元素Element1,则需要将其添加到“ SelectedList”。 If I then select Element2 from Tab2, then Element2 has to appear in "SelectedList", under Element1. 如果然后从Tab2中选择Element2,则Element2必须出现在Element1下的“ SelectedList”中。

Now, I could possibly create a temporary model combining $scope.model1 and $scope.model2 called $scope.selectedList and do 现在,我可以创建一个合并了$ scope.model1和$ scope.model2的临时模型,称为$ scope.selectedList并执行

<ul id="SelectedList" ng-repeat="listItem in selectedList">...</ul>

But I'm looking to see if there is a cleaner method that satisfies two-way data binding, something like: 但是我正在寻找是否有一种更清洁的方法可以满足双向数据绑定,例如:

<ul id="SelectedList" ng-repeat="listItem in model1+model2">...</ul>

Is there a better solution to this? 有更好的解决方案吗? Is there maybe a completely different approach to this? 可能有完全不同的方法吗?

如果列表是数组,则可以使用其concat方法将其加入:

    <ul ng-repeat="item in arrayList1.concat(arrayList2)">...</ul>

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

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