//页面初次渲染时 调用的方法
async onLoad() {
//设置一个转圈,告诉用户正在加载数据
uni.showLoading({
title: '加载中'
});
const result = await db
.collection('instruct')
.limit(500)
.get(); //加载数据方法
let list = result.result.data;
console.log("获取到list",list)
//修改从数据库取得值,附加一些属性进去 注意:要在绑定界面之前 否则修改属性值不会动态变化界面
let types = [];
list.forEach(item => {
item.checked = false;
if (item.items) {
let index = item.items.findIndex(x => typeof x.isDefault != 'undefined' && x.isDefault);
if (index != -1) {
item.selectIndex = index;
item.selectText = item.items[index].name;
} else {
item.selectIndex = null;
item.selectText = null;
}
}
if (typeof item.type_name == "undefined" || item.type_name == null) {
item.type_name = '通用';
}
if (types.indexOf(item.type_name) == -1) {
types.push(item.type_name)
}
});
this.types = types;
this.list = list; //赋值给界面属性 会自动更新界面 完成渲染
//加载完数据后结束转圈
uni.hideLoading();
},
instruct表的schema
{
"bsonType": "object",
"required": [],
"permission": {
"read": true,
"create": false,
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"name": {
"bsonType": "string",
"title": "指令名称",
"description": "指令名称,用于前端显示",
"maxLength": 20,
"trim": "both"
},
"type_name": {
"bsonType": "string",
"title": "分类名称",
"description": "分类名称",
"maxLength": 20,
"trim": "both"
},
"description": {
"bsonType": "string",
"title": "描述",
"description": "对指令的描述",
"maxLength": 50,
"trim": "both"
},
"items": {
"bsonType": "array",
"title": "选项集合",
"description": "选项集合",
"arrayType": "object",
"properties": {
"name": {
"bsonType": "string",
"title": "选项名称",
"description": "选项名称",
"maxLength": 20,
"trim": "both"
},
"data": {
"bsonType": "array",
"title": "指令数据",
"description": "指令数据",
"arrayType": "int"
},
"data_url": {
"bsonType": "string",
"title": "指令数据",
"description": "指令数据"
},
"isDefault": {
"bsonType": "bool",
"title": "是否默认",
"description": "是否默认"
}
}
}
}
}
Devillo
4.41.2024121203-alpha 此版本还是报错了
2024-12-15 18:23