0
如何在NativeScript中將數組從最早到最新排序?在NativeScript中對列表視圖進行排序
我的代碼:
import observableArray = require("data/observable-array");
var orderListRaw = new observableArray.ObservableArray([]);
var orderList = orderListRaw.sort((a:number, b:number) => {return a - b;});
function news(args) {
fetch('https://testapi.local/', {
method: 'GET',
}).then(response => {
return response.json();
}).then(function(r) {
var res = r.results;
orderList.length = 0
console.log(JSON.stringify(res));
for (var i = 0; i < res.length; i++) {
var order = {
createdAt: res[i].createdAt,
title: res[i].title,
desc: res[i].desc,
image: res[i].image.url
}
orderList.push(order);
}
},
function(e) {
console.log(e);
});
};
的結果是,我的數組排序還是在最早到最晚的。 非常感謝
所以你想按'createdAt'的順序排序數組,不是嗎? –