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

妖狐艹你老母 2023-10-05 16:42 62阅读 0赞

1 多选下拉框加载时设置默认选中值

1.1 setValues+勾选选中行的复选框

  1. unction BindMultiListCode(objId,comboxData,values){
  2. $('#' + objId).combobox({
  3. data: comboxData,
  4. valueField: 'Code',
  5. textField: 'CodeName',
  6. panelHeight: 'auto',
  7. editable: false,
  8. showblank: true,
  9. multiple: true,
  10. formatter: function (row) {
  11. var opts = $(this).combobox('options');
  12. return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];
  13. },
  14. onLoadSuccess: function (data) {
  15. //多选下拉框加载成功后设置默认选中值
  16. $('#' + objId).combobox("setValues", values);
  17. for (var i = 0; i < values.length; i++) {
  18. var value = values[i];
  19. var children = $(target).combobox("panel").children();
  20. $.each(children, function (index, obj) {
  21. if (value == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
  22. obj.children[0].checked = true;
  23. }
  24. });
  25. }
  26. },
  27. onSelect: function (row) {
  28. var opts = $(this).combobox("options");
  29. var objCom = null;
  30. var children = $(this).combobox("panel").children();
  31. $.each(children, function (index, obj) {
  32. if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
  33. obj.children[0].checked = true;
  34. }
  35. });
  36. },
  37. onUnselect: function (row) {
  38. var opts = $(this).combobox("options");
  39. var objCom = null;
  40. var children = $(this).combobox("panel").children();
  41. $.each(children, function (index, obj) {
  42. if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
  43. obj.children[0].checked = false;
  44. }
  45. });
  46. }
  47. });
  48. }

1.2 select

  1. unction BindMultiListCode(objId,comboxData,values){
  2. $('#' + objId).combobox({
  3. data: comboxData,
  4. valueField: 'Code',
  5. textField: 'CodeName',
  6. panelHeight: 'auto',
  7. editable: false,
  8. showblank: true,
  9. multiple: true,
  10. formatter: function (row) {
  11. var opts = $(this).combobox('options');
  12. return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];
  13. },
  14. onLoadSuccess: function (data) {
  15. //多选下拉框加载成功后设置默认选中值
  16. $('#' + objId).combobox("setValues", values);
  17. for (var i = 0; i < values.length; i++) {
  18. var value = values[i];
  19. $('#' + objId).combobox('select', value.toString());
  20. }
  21. },
  22. onSelect: function (row) {
  23. var opts = $(this).combobox("options");
  24. var objCom = null;
  25. var children = $(this).combobox("panel").children();
  26. $.each(children, function (index, obj) {
  27. if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
  28. obj.children[0].checked = true;
  29. }
  30. });
  31. },
  32. onUnselect: function (row) {
  33. var opts = $(this).combobox("options");
  34. var objCom = null;
  35. var children = $(this).combobox("panel").children();
  36. $.each(children, function (index, obj) {
  37. if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
  38. obj.children[0].checked = false;
  39. }
  40. });
  41. }
  42. });
  43. }

2 多选下拉框加载时设置默认选中前几项

2.1 setValues+勾选选中行的复选框

  1. function BindMultiListCode(objId,comboxData,selectCount){
  2. var i = 1;
  3. var values = [];
  4. $('#' + objId).combobox({
  5. data: comboxData,
  6. valueField: 'Code',
  7. textField: 'CodeName',
  8. panelHeight: 'auto',
  9. editable: false,
  10. showblank: true,
  11. multiple: true,
  12. formatter: function (row) {
  13. var opts = $(this).combobox('options');
  14. //获取前几项
  15. if (i++ <= selectCount) {
  16. values.push(row[opts.valueField]);
  17. }
  18. return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];
  19. },
  20. onLoadSuccess: function (data) {
  21. //多选下拉框加载成功后设置默认选中值
  22. $('#' + objId).combobox("setValues", values);
  23. for (var i = 0; i < values.length; i++) {
  24. var value = values[i];
  25. var children = $(target).combobox("panel").children();
  26. $.each(children, function (index, obj) {
  27. if (value == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
  28. obj.children[0].checked = true;
  29. }
  30. });
  31. }
  32. },
  33. onSelect: function (row) {
  34. var opts = $(this).combobox("options");
  35. var objCom = null;
  36. var children = $(this).combobox("panel").children();
  37. $.each(children, function (index, obj) {
  38. if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
  39. obj.children[0].checked = true;
  40. }
  41. });
  42. },
  43. onUnselect: function (row) {
  44. var opts = $(this).combobox("options");
  45. var objCom = null;
  46. var children = $(this).combobox("panel").children();
  47. $.each(children, function (index, obj) {
  48. if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
  49. obj.children[0].checked = false;
  50. }
  51. });
  52. }
  53. });
  54. }

2.2 select

  1. function BindMultiListCode(objId,comboxData,selectCount){
  2. var i = 1;
  3. var values = [];
  4. $('#' + objId).combobox({
  5. data: comboxData,
  6. valueField: 'Code',
  7. textField: 'CodeName',
  8. panelHeight: 'auto',
  9. editable: false,
  10. showblank: true,
  11. multiple: true,
  12. formatter: function (row) {
  13. var opts = $(this).combobox('options');
  14. //获取前几项
  15. if (i++ <= selectCount) {
  16. values.push(row[opts.valueField]);
  17. }
  18. return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];
  19. },
  20. onLoadSuccess: function (data) {
  21. //多选下拉框加载成功后设置默认选中值
  22. $('#' + objId).combobox("setValues", values);
  23. for (var i = 0; i < values.length; i++) {
  24. var value = values[i];
  25. $('#' + objId).combobox('select', value.toString());
  26. }
  27. },
  28. onSelect: function (row) {
  29. var opts = $(this).combobox("options");
  30. var objCom = null;
  31. var children = $(this).combobox("panel").children();
  32. $.each(children, function (index, obj) {
  33. if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
  34. obj.children[0].checked = true;
  35. }
  36. });
  37. },
  38. onUnselect: function (row) {
  39. var opts = $(this).combobox("options");
  40. var objCom = null;
  41. var children = $(this).combobox("panel").children();
  42. $.each(children, function (index, obj) {
  43. if (row[opts.valueField] == obj.getAttribute("value") && obj.children && obj.children.length > 0) {
  44. obj.children[0].checked = false;
  45. }
  46. });
  47. }
  48. });
  49. }

发表评论

表情:
评论列表 (有 0 条评论,62人围观)

还没有评论,来说两句吧...

相关阅读