在某些时候 cascader 并不是必填的,且须要有‘全副’或‘请抉择’等选项,须要在初始化前对数据进行解决:
window.renderSelect = function (cascader,callback) {
ajax({
url: "xx/tree",
method: "get",
success: function (resp) {
var data1 = resp.data.children;
// 应用之前最好深拷贝一下树数据,避免后续操作影响到到原数据
data1 = JSON.parse(JSON.stringify(data1));
// 应用数组办法在后面减少一个选项
data1.unshift({value: "", label:" 全副 "});
cascader({
elem: "#dept",
data: data1,
value: [],
canParentSelect: true,
success: function (valData, labelData) {treeid = String(valData[valData.length - 1]);
},
});
callback && callback(resp.data)
},
error: function (res) {layer.msg(res.description);
},
});
};