EasyUI combobox(多选下拉框)加载时设置默认值(设置默认选中值、设置默认选中前几项)
1 多选下拉框加载时设置默认选中值
1.1 setValues+勾选选中行的复选框
unction BindMultiListCode(objId,comboxData,values){$('#' + objId).combobox({data: comboxData,valueField: 'Code',textField: 'CodeName',panelHeight: 'auto',editable: false,showblank: true,multiple: true,formatter: function (row) {var opts = $(this).combobox('options');return '' + row[opts.textField];},onLoadSuccess: function (data) {//多选下拉框加载成功后设置默认选中值$('#' + objId).combobox("setValues", values);for (var i = 0; i < values.length; i++) {var value = values[i];var children = $(target).combobox("panel").children();$.each(children, function (index, obj) {if (value == obj.getAttribute("value") && obj.children && obj.children.length > 0) {obj.children[0].checked = true;}});}},onSelect: function (row) {var opts = $(this).combobox("options");var objCom = null;var children = $(this).combobox("panel").children();$.each(children, function (index, obj) {if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {obj.children[0].checked = true;}});},onUnselect: function (row) {var opts = $(this).combobox("options");var objCom = null;var children = $(this).combobox("panel").children();$.each(children, function (index, obj) {if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {obj.children[0].checked = false;}});}});
}
1.2 select
unction BindMultiListCode(objId,comboxData,values){$('#' + objId).combobox({data: comboxData,valueField: 'Code',textField: 'CodeName',panelHeight: 'auto',editable: false,showblank: true,multiple: true,formatter: function (row) {var opts = $(this).combobox('options');return '' + row[opts.textField];},onLoadSuccess: function (data) {//多选下拉框加载成功后设置默认选中值$('#' + objId).combobox("setValues", values);for (var i = 0; i < values.length; i++) {var value = values[i];$('#' + objId).combobox('select', value.toString());}},onSelect: function (row) {var opts = $(this).combobox("options");var objCom = null;var children = $(this).combobox("panel").children();$.each(children, function (index, obj) {if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {obj.children[0].checked = true;}});},onUnselect: function (row) {var opts = $(this).combobox("options");var objCom = null;var children = $(this).combobox("panel").children();$.each(children, function (index, obj) {if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {obj.children[0].checked = false;}});}});
}
2 多选下拉框加载时设置默认选中前几项
2.1 setValues+勾选选中行的复选框
function BindMultiListCode(objId,comboxData,selectCount){var i = 1;var values = [];$('#' + objId).combobox({data: comboxData,valueField: 'Code',textField: 'CodeName',panelHeight: 'auto',editable: false,showblank: true,multiple: true,formatter: function (row) {var opts = $(this).combobox('options');//获取前几项if (i++ <= selectCount) {values.push(row[opts.valueField]);}return '' + row[opts.textField];},onLoadSuccess: function (data) {//多选下拉框加载成功后设置默认选中值$('#' + objId).combobox("setValues", values);for (var i = 0; i < values.length; i++) {var value = values[i];var children = $(target).combobox("panel").children();$.each(children, function (index, obj) {if (value == obj.getAttribute("value") && obj.children && obj.children.length > 0) {obj.children[0].checked = true;}});}},onSelect: function (row) {var opts = $(this).combobox("options");var objCom = null;var children = $(this).combobox("panel").children();$.each(children, function (index, obj) {if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {obj.children[0].checked = true;}});},onUnselect: function (row) {var opts = $(this).combobox("options");var objCom = null;var children = $(this).combobox("panel").children();$.each(children, function (index, obj) {if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {obj.children[0].checked = false;}});}});
}
2.2 select
function BindMultiListCode(objId,comboxData,selectCount){var i = 1;var values = [];$('#' + objId).combobox({data: comboxData,valueField: 'Code',textField: 'CodeName',panelHeight: 'auto',editable: false,showblank: true,multiple: true,formatter: function (row) {var opts = $(this).combobox('options');//获取前几项if (i++ <= selectCount) {values.push(row[opts.valueField]);}return '' + row[opts.textField];},onLoadSuccess: function (data) {//多选下拉框加载成功后设置默认选中值$('#' + objId).combobox("setValues", values);for (var i = 0; i < values.length; i++) {var value = values[i];$('#' + objId).combobox('select', value.toString());}},onSelect: function (row) {var opts = $(this).combobox("options");var objCom = null;var children = $(this).combobox("panel").children();$.each(children, function (index, obj) {if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {obj.children[0].checked = true;}});},onUnselect: function (row) {var opts = $(this).combobox("options");var objCom = null;var children = $(this).combobox("panel").children();$.each(children, function (index, obj) {if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {obj.children[0].checked = false;}});}});
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!