更新时间:2020-10-20 08:16:52
基于jquery,支持键盘操作 数据格式:
var _data = [{ value: 'shanghai', label: '上海', children: [{ value: 'shanghaishi', label: '上海市', children: [{ value: 'baoshan1', label: '宝山区saa发送飞洒发送' }, { value: 'fengxian1', label: '奉贤区' }] }] }];
我对该级联下拉控件的默认值做了一个简单扩展,代码如下:
ZdCascader.prototype.getNode = function(id) { var ddldata = this.options.data; let result = null; var resultarr = []; var isfinish = false; function getTreeItem(data, id) { for (var g = 0; g < data.length; g++) { //0,1,2 var item = data[g]; if (isfinish) { return; } var index = data.map(n => n.value).indexOf(id); if (index > -1) { isfinish = true; resultarr[item.level] = data[index].label; break; } else { resultarr[item.level] = item.label; if (item.children) { getTreeItem(item.children, id); } else { break; } } } } getTreeItem(ddldata, id); result = resultarr.join(this.options.range); this.$el.val(result).focus(); };