内创建父DIV我从JSON字符串25个项目。每个项目都带有一个名为“InRowPlcement”的键,值分配为“0”或“1”或“2”等。NG重复
{"ItemID":"516","ItemName":"Newzeland Lake Tysonno","InRowPlcement":0},
{"ItemID":"514","ItemName":"Newzeland Lake Tysonno","InRowPlcement":0},
{"ItemID":"546","ItemName":"Underworld Lives","InRowPlcement":0},
{"ItemID":"527","ItemName":"In a holiday beach","InRowPlcement":1},
{"ItemID":"542","ItemName":"Underworld Lives","InRowPlcement":1},
{"ItemID":"525","ItemName":"Lake somewhere","InRowPlcement":1},
{"ItemID":"540","ItemName":"Coral Structure at Andaman","InRowPlcement":1},
{"ItemID":"569","ItemName":"Ice Rock, Ireland","InRowPlcement":2}
的意图是,第三行等中放置“0”“InRowPlacement”项在第一行中,“1”的第二行中,“2”。项目的数量在每行中可能会有所不同。它可能从1到5在一行中。
我开始了NG-重复
<div class="ROW" ng-repeat="item in items">
<div class="COLUMN">{{item.ItemName}}<div>
</div>
我需要的结果应该是像
<div class="ROW">
<div class="COLUMN">Newzeland Lake Tysonno<div>
<div class="COLUMN">Newzeland Lake Tysonno<div>
<div class="COLUMN">Underworld Lives<div>
</div>
<div class="ROW">
<div class="COLUMN">In a holiday beach<div>
<div class="COLUMN">Underworld Lives<div>
<div class="COLUMN">Lake somewhere<div>
<div class="COLUMN">Coral Structure at Andaman<div>
</div>
在此先感谢您的帮助。
SOLUTION UPDATE:
基于由@vp_arth提供的逻辑,这里是实际的代码,这对我的作品
var view_rows = {};
angular.forEach(response.data, function(InRowPlcement,index){
if (!view_rows[response.data[index].InRowPlcement]) view_rows[response.data[index].InRowPlcement] = [];
view_rows[response.data[index].InRowPlcement].push(response.data[index]);
});
groups = view_rows;
为什么唯独没有改变的数据结构视图层?迭代并在控制器中构建所需的内容。 –
@vp_arth,你能否给我一些细节,我只是想插入“
inserting parts of DOM like this too smells. Just think angular. There is a data and there is directive ('ng-repeat') to represent this data. You can write your own directive with custom behavior. You shouldn't manipulate with raw HTML parts (like '