对于select,我可以使用如下语句动态改变option
var selMan = document.getElementsByName("CurrentMan")[0];
selMan.options.length = 1;
selMan.options[selMan.options.length] = new Option("7","李四1");
selMan.options[selMan.options.length] = new Option("8","李四2");
但发现使用EXTJS转换select为combo后,动态改变option则报错。Ext.onReady(function() {
var transformed = Ext.create('Ext.form.field.ComboBox', {
    typeAhead: true,
    transform: 'CurrentMan',
    emptyText: '请选择或输入',
    width: 100,
    forceSelection: true
});
});
<select name="CurrentMan">
          <option value="" Selected></option>
          <option value="1">张三1</option>
          <option value="2">张三2</option>
          <option value="3">张三3</option>
          <option value="4">张三4</option>
          <option value="5">张三5</option>
        </select>
我想可以两种解决
1、在动态改变option前,把EXTJS失效,也就是还原为select模式,在动态改动,最后再使用、EXTJS转换,但不知道怎么做?
2、直接使用EXTJS来动态改变,但不知道怎么写代码。以上两点建议,各位帮忙看看。

解决方案 »

  1.   

    通过EXTJS转换select框后,不能再使用如下JS脚本了。怎么办?var selMan = document.getElementsByName("CurrentMan")[0];
    selMan.options.length = 1;
    selMan.options[selMan.options.length] = new Option("7","李四1");
    selMan.options[selMan.options.length] = new Option("8","李四2");
      

  2.   

    我这里4.1EXTJS 是执行成功的,,
      

  3.   

    我测试了extjs-4.1.0,仍然抱错,报"options为空或不是对象"
    <!-- ExtJS -->
    <link rel="stylesheet" type="text/css" href="extjs-4.1.0/resources/css/ext-all.css" />
    <script type="text/javascript" src="extjs-4.1.0/ext-all.js"></script>
    <script type="text/javascript">
    <!--
    Ext.onReady(function() {
        //Ext.tip.QuickTipManager.init();
    var transformed = Ext.create('Ext.form.field.ComboBox', {
        typeAhead: true,
        transform: 'CurrentMan',
        emptyText: '请选择或输入',
        width: 100,
        forceSelection: true
    });
    });function AddMans()
    {
        ProjectCode = document.form.ProjectCode.value;
        url = "/zygl/LoadingPro_FP.asp?ProjectCode=" + ProjectCode; //调用页面
        var http = new ActiveXObject("Microsoft.XMLHTTP");
        http.open("post", url, false);
        http.send();
        var str = http.responseText;    var selMan = document.getElementsByName("CurrentMan")[0];
        selMan.options.length = 1;    if (str != "")
        {
            strD = str.split(",");
            for (q = 0; q < strD.length; q++)
            {
                pos = strD[q].indexOf("-");
                selMan.options[selMan.options.length] = new Option(strD[q].slice(0,pos), strD[q].slice(pos + 1));
            }
        }
        else
        {
             <%SQLQuery2 = "select EmployeeId,EmployeeName FROM V_EmployeeTable where PosTtitleId<>'ZC01' and  PosTtitleId<>'ZC02' and YesNoExistID='CZ01' and DepartId in ('BM22','BM23','BM24','BM25')"
               Set RS2 = cn.Execute(SQLQuery2)
               do while not rs2.eof%> 
               selMan.options[selMan.options.length] = new Option("<%=trim(rs2(1))%>", "<%=trim(rs2(0))%>");
               <%rs2.movenext
                 loop
                 RS2.close
                 set RS2 = nothing%> 
        }
    }
    -->
    </script><input name="ProjectCode" id="ProjectCode" type="text" onpropertychange="AddMans()" value=""/>
    <select name="CurrentMan">
              <option value="" Selected></option>
              <option value="1">张三1</option>
              <option value="2">张三2</option>
              <option value="3">张三3</option>
              <option value="4">张三4</option>
              <option value="5">张三5</option>
            </select>
      

  4.   

    给你段3.4下的代码参考下:var record=[];
    var values='1,2';
    var texts='选项1,选项2';
    var valueArr=values.split(',');
    var textArr=texts.split(',');
    for(var i=0;i<valueArr.length;i++)
    {
    record.push([valueArr[i],textArr[i]]);
    }
    transformed.store.loadData(record,false); //transformed为你的Combobox对象
      

  5.   

    谢谢,搞定,另外在前面加一句transformed.clearValue();就完美了,谢谢