200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > EasyUI combobox(多选下拉框)加载时设置默认值(设置默认选中值 设置默认选中前几项)

EasyUI combobox(多选下拉框)加载时设置默认值(设置默认选中值 设置默认选中前几项)

时间:2023-03-02 04:45:14

相关推荐

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 '<input type="checkbox" class="combobox-checkbox">' + 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 '<input type="checkbox" class="combobox-checkbox">' + 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 '<input type="checkbox" class="combobox-checkbox">' + 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 '<input type="checkbox" class="combobox-checkbox">' + 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;}});}});}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。