如何从片段属性 skärm 的嵌套值中对我的 ng-repeat 列表进行排序:我的控制器如下所示:
'use strict';
/* Controllers */
function PhoneListCtrl($scope){
$scope.phones = [
{"name" : "Samsung Galaxy S4",
"snippet" : { "Operativsystem" : "Android 4.2.2",
"Skärm" : "4,99 tum",
"CPU" : "Quad-core 1,6GHz",
"Kamera, bak" : "13 MP",
"Kamera, fram" : "1,9 MP",
"Övrigt" : "Närfältskommunikation (Eng. near field communication, NFC)"
},
"date" : "2012-04-27T00:00:00.000Z"
},
{"name" : "iPhone 5",
"snippet" : { "Operativsystem" : "iOS 7",
"Skärm" : "4 tum",
"CPU" : "Apple A6 1,3GHz dual core",
"Kamera, bak" : "8 MP",
"Kamera, fram" : "1,2 MP",
"Övrigt" : "-"
},
"date" : "2012-09-21T00:00:00.000Z"
},
{"name" : "iPhone 5s",
"snippet" : { "Operativsystem" : "iOS 7",
"Skärm" : "42 tum",
"CPU" : "Apple A7 1,3 GHz dual core",
"Kamera, bak" : "8 MP",
"Kamera, fram" : "1,2 MP",
"Övrigt" : "-"
},
"date" : "2013-09-20T00:00:00.000Z"
}
]
};
基于字母和日期的排序工作,但我如何使用 Skärm 的嵌套值作为排序参数?
<b>Sort by: </b>
<select ng-model="sortByProp">
<option value="name">Alfabetiskt</option>
<option value="date">Nyast</option>
<option value="snippet.Skärm">Skärmstorlek</option>
</select>
</div>
<div class="span10">
<h1>The future of mobile devices</h1>
<ul class="phonesListing">
<li ng-repeat="phone in phones | filter:query | orderBy:sortByProp">
<h3>{{phone.name}}</h3>
<ul>
<li ng-repeat="(key,value) in phone.snippet">
<b>{{key}}:</b> {{value}}
</li>
</ul>
</li>
</ul>
<p>Total number of phones: {{phones.length}}</p>
</div>