有没有办法在javascript中订购这些(alal SELECT * FROM this ORDERBY ....)。因此,如果我只是想将新的列表元素从对象附加到 DOM,但想控制顺序之类的东西。
var example = [
{id:1, data: { val1: 'val1', val2: 'val2'}, orderById: 313},
{id:2, data: { val1: 'val1', val2: 'val2'}, orderById: 312},
];
var buildString = '';
for ( var i = 0; i < example.length; i++ ) {
// wondering if there is another approach so that i could control the order as I build the string
buildString += "<li class='example-class'>" + example[i].data.val1 + "</li>";
}
$("#some-ul").html('').append(buildString);
所以如果有更好的方法来实现这个想法,我有兴趣学习......