跳过角JS NG-重复JSON排序 [英] Skip ng-repeat JSON ordering in Angular JS
问题描述
有谁知道我怎么能跳过 JSON订货时,干脆我用NG-重复(在一个无痛的方式可能)?
Does anybody know how I can SKIP JSON ordering altogether when I use ng-repeat (in a painless way probably)?
例如,我的源JSON看起来是这样的 -
For example, my source JSON looks something like this -
{
"title": "Title",
"description": "Description",
"moreInfo": "Moreinformation"
}
在我NG重复使用它,它下令按字母顺序。事情是这样的 -
Once I use it in ng-repeat, it orders them alphabetically. Something like this -
{
"description": "Description",
"moreInfo": "Moreinformation",
"title": "Title"
}
我的NG-重复看起来是这样的 -
My ng-repeat looks something like this -
<div ng-repeat="(key,data) in items">
<span class="one"> {{key}} </span>
<span class="two"> {{data}} </span>
</div>
我见过的人有钥匙的一个单独的数组,并用它们来识别JSON对象,最终避免字母排序。
I've seen people having a separate array of the keys and using them to identify the JSON objects, ultimately avoiding alphabetical sorting.
有一种优雅的方式来做到这一点?
Is there an elegant way to do this?
推荐答案
在谷歌研究小组发现尼斯的解决方法:
Nice workaround found at google groups:
<div ng-repeat="key in notSorted(data)" ng-init="value = data[key]">
<pre>
key: {{key}}
value: {{value}}
</pre>
</div>
和范围:
$scope.data = {
'key4': 'data4',
'key1': 'data1',
'key3': 'data3',
'key2': 'data2',
'key5': 'data5'
};
$scope.notSorted = function(obj){
if (!obj) {
return [];
}
return Object.keys(obj);
}
工作: http://jsfiddle.net/DnEXC/
原文:<一href=\"https://groups.google.com/forum/#!topic/angular/N87uqMfwcTs\">https://groups.google.com/forum/#!topic/angular/N87uqMfwcTs
这篇关于跳过角JS NG-重复JSON排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!