var mockData = [ { id: "无锡", text: "无锡", isParent: true, }, { id: "锡山区", text: "锡山区", pId: "无锡", isParent: true, }, { id: "安镇街道", text: "安镇街道", pId: "锡山区", }, { id: "滨湖区", text: "滨湖区", pId: "无锡", }, { id: "南京", text: "南京", isParent: true, }, { id: "建邺区", text: "建邺区", pId: "南京", } ]; 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.button_tree", chooseType: 0, layouts: [ { type: "bi.vertical", }, ], }, items: this._formatItems(mockData) } }, _formatItems: function (items) { var nodes = BI.map(items, function (index, item) { return BI.extend({ type: item.isParent ? "bi.example.single_custom_tree.node" : "bi.example.single_custom_tree.item" }, item) }) return this.traversalLayers(BI.Tree.transformToTreeFormat(nodes), 0); }, traversalLayers: function (items, layer) { var self = this; BI.each(items, function (index, item) { item.layer = layer; if (item.children) { self.traversalLayers(item.children, layer + 1) } }) return items; } }); BI.shortcut("bi.example.single_custom_tree", Tree); BI.createWidget({ type: "bi.example.single_custom_tree", element: "#wrapper" })