动态创建自定义数据集
引用数据集组件的js文件
import TableData from "$UI/wxsys/comps/tableData/tableData";
定义需要创建的列信息并进行new
(1). defCols中json的格式定义列信息,如下是定义了code、name、id三个列,并且设置类的类型以及规则
(2).initData中定义默认创建带的初始化数据,也可以不带
(3).options中定义idColumn、autoMode等
autoMode的值可以有三个选择:load、new、null;load是默认加载initData中初始化的数据,new是默认新增,null是不加载也不新增需要的时候自己操作
(4).new方法中this就是当前页面,helloData是创建的数据集的id,可以通过this.comp("helloData")获取数据对象
var config = {
"defCols": {
code: {
define: "code",
label: "编码",
type: "string",
rules: {
"readonly": function ($row) { },
"default": function () { },
"required": {
"fn": function ($row) { },
"msg": "",
},
"constraint": {
"fn": function ($row) { },
"msg": "",
},
"calculate": function ($row) { return "aaa"}
}
},
name: {
define: "name",
label: "名称",
type: "string"
},
id: {
define: "name",
label: "名称",
type: "string"
}
},
"initData": [
{
"code": "1",
"name": "1",
"id": "1"
},
{
"code": "2",
"name": "2",
"id": "2"
}
],
"filters": {},
"options": {
"limit": 20,
"orderBy": [],
"depends": [],
"isMain": false,
"autoMode": "load",
"directDelete": true,
"confirmDelete": true,
"confirmRefreshText": "",
"allowEmpty": false,
"confirmDeleteText": "",
"confirmRefresh": true,
"idColumn": "id",
"dataReadonly": function ($data) { },
"deleteConstraint": function ($row) { },
"deleteConstraintMsg": function ($row) { }
}
};
var data = new TableData(this, "helloData", config);