autojs列表排序
```javascript
"ui";
ui.layout(
<vertical>
<button id="年龄正序">年龄正序</button>
<button id="年龄倒序">年龄倒序</button>
<list id="list">
<vertical>
<text id="name" textSize="16sp" textColor="#000000" text="姓名: {{name}}" />
<text id="age" textSize="16sp" textColor="#000000" text="年龄: {{age}}岁" />
<button id="deleteItem" text="删除" />
</vertical>
</list>
</vertical>
);
ui.年龄正序.click(function () {
items.sort(function (a, b) {
if (a.age < b.age) {
return -1;
} else if (a.age === b.age) {
return 0;
} else {
return 1;
}
});
});
ui.年龄倒序.click(function () {
items.sort(function (a, b) {
if (a.age < b.age) {
return 1;
} else if (a.age === b.age) {
return 0;
} else {
return -1;
}
});
});
var items = [
{
name: "小明",
age: 18,
},
{
name: "小红",
age: 30,
},
{
name: "小东",
age: 19,
},
];
ui.list.setDataSource(items);
ui.list.on("item_click", function (item, i, itemView, listView) {
toast("被点击的人名字为: " + item.name + ",年龄为: " + item.age);
});
ui.list.on("item_bind", function (itemView, itemHolder) {
itemView.deleteItem.on("click", function () {
let item = itemHolder.item;
toast("被删除的人名字为: " + item.name + ",年龄为: " + item.age);
log(itemHolder.position);
items.splice(itemHolder.position, 1);
});
});
```
**## 声明**
部分内容来自网络
本教程仅用于学习, 禁止用于其他用途