实现jquery Easyui中combotree,combobox控件的动态选中

濮阳烨然
2023-12-01

html页面:

<tr style="line-height:35px">
                    <td style="width: 24%;text-align:center;">
                        <span i18nName="brno" class="i18n"></span>
                    </td>
                    <td style="width: 75%;text-align:left;">
                    <input id="org" multiple style="width:250px;">
                    </td>
                </tr>
                <tr style="line-height:35px">
                    <td style="width: 24%;text-align:center;">
                        <span i18nName="post" class="i18n"></span>
                    </td>
                    <td style="text-align:left;">
                      <select id="post"  prompt ="请选择岗位"  class="easyui-combobox"  style="width:269px;"
                        data-options="editable:false,required:true,missingMessage:'请选择岗位'" ></select>
                    </td>
                </tr>

控件初始化:

$("#pid").combobox({
        valueField:'p_id',
        textField:'p_name',
        height:23,
        editable:false,
        required:true
    });
    papersinfo = selectPaper(pid);

要加载的数据:

var brno = new Array();    
var postname = new Array(); 
for(var i = 0;i < result2.length; i++){
           var jsonstr2 = JSON.stringify(result2[i]);
           var sd = eval('(' + jsonstr2 + ')');
           brno.push(sd.brno);
           postname.push(sd.postname);
    }

根据数据动态选中:

$('#org').combotree({
        url: '......',
        required: true,
        animate:true,
        cascadeCheck:false,
        onCheck:function(node, checked){
            updatePosts(node, checked);
        },
        onLoadSuccess:function(node,data){
              var t = $('#org').combotree('tree');
              var nodes=t.tree('getChecked', 'unchecked');
              for ( var int = 0; int < nodes.length; int++) {
                  var node = nodes[int];
                  var org = new Object();
                  org.brno = node.id;
                  for(var i = 0; i<brno.length; i++){
                      if(org.brno == brno[i]){
                          t.tree('check',node.target);
                      }
                  }
              }
              data = $('#post').combobox('getData');
              for(var i = 0; i < data.length; i++){
                    for(var j = 0; j < postname.length; j++){
                         if(data[i].postname == postname[j]){
                               $('#post').combobox('select',data[i].postno);
                          }
                      }
               }
            }
    });
 类似资料: