You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.6 KiB

var mockData = [
{
id: "无锡",
text: "无锡",
isParent: true,
layer: 0
}, {
id: "锡山区",
text: "锡山区",
pId: "无锡",
isParent: true,
layer: 1
}, {
id: "安镇街道",
text: "安镇街道",
pId: "锡山区",
layer: 2
}, {
id: "滨湖区",
text: "滨湖区",
pId: "无锡",
layer: 1
}, {
id: "南京",
text: "南京",
isParent: true,
layer: 0
}, {
id: "建邺区",
text: "建邺区",
pId: "南京",
layer: 1
}
];
var Tree = BI.inherit(BI.Widget, {
render: function () {
return {
type: "bi.custom_tree",
expander: {
type: "bi.expander",
isDefaultInit: false,
el: {},
popup: {
type: "bi.custom_tree",
},
},
el: {
type: "bi.loader",
next: false,
el: {
type: "bi.button_tree",
chooseType: -1,
layouts: [
{
type: "bi.vertical",
},
],
},
},
itemsCreator: BI.bind(this._itemsCreator, this),
listeners: [
{
eventName: BI.Controller.EVENT_CHANGE,
action: function (type, value) {
if (type === BI.Events.CLICK) {
this.setValue(value);
}
},
},
],
}
},
_formatItems: function (items) {
return BI.map(items, function (index, item) {
return BI.extend({
type: item.isParent ? "bi.example.sync_custom_tree.node" : "bi.example.sync_custom_tree.item"
}, item)
})
},
_itemsCreator: function (op, callback) {
var items = [];
if (!op.node) { // 初次回调的时候是没有节点信息的
items = BI.filter(mockData, function (index, item) {
return BI.isNull(item.pId);
})
} else {
var id = op.node.id;
items = BI.filter(mockData, function (index, item) {
return item.pId === id;
})
}
callback(this._formatItems(items))
},
});
BI.shortcut("bi.example.sync_custom_tree", Tree);
BI.createWidget({
type: "bi.example.sync_custom_tree",
element: "#wrapper"
})