主要代码如下: <script type="text/javascript"> 
    
Ext.onReady(function(){   Ext.create('Ext.form.Panel', { 
    bodyPadding: 10, 
    width      : 300, 
    title      : 'Pizza Order', 
    items: [ 
        { 
            xtype      : 'fieldcontainer', 
            fieldLabel : 'Toppings', 
            defaultType: 'checkboxfield', 
            items: [ 
                { 
                    boxLabel  : 'Anchovies', 
                    name      : 'topping', 
                    inputValue: '1', 
                    id        : 'checkbox1' 
                }, { 
                    boxLabel  : 'Artichoke Hearts', 
                    name      : 'topping', 
                    inputValue: '2', 
                    checked   : true, 
                    id        : 'checkbox2' 
                }, { 
                    boxLabel  : 'Bacon', 
                    name      : 'topping', 
                    inputValue: '3', 
                    id        : 'checkbox3'               
                } 
            ] 
        } 
    ], 
    renderTo: Ext.getBody() 
}); var array1 = document.getElementsByName("topping");alert(array1);alert(array1.length);// 要实现类似这样的功能,这里无效 
var array2 = Ext.query("*[name=topping]");alert(array2);alert(array2.length);//用query也无 效,array值为“” 
});  
    </script>      再补充说明下,就是想通过复选框的name值topping来求其数组,这里我用了两种方式,都无效, document.getElementsByName("topping");是普通js中使用的,另一种是ext中使用的,我用了query,也无效,不知 道问题出在哪里了? 

解决方案 »

  1.   

    item中的name:topping并不是对应的在dom中定义的checkbox,所以这种方式不行的。
      

  2.   

    var v = Ext.getName('topping');
    alert(v);复制上看看什么反应
      

  3.   

    我觉得楼主好像用错控件了、应该用checkboxgroup这个东西吧
      

  4.   

    var array2 = Ext.query("*[name= ‘ topping ’ ]")
      

  5.   

    你不能直接用document ext渲染完了还不知道把dom元素改成啥样了呢 呵呵 没有这个name的元素也说不定
    给你专门写了个方法 可以根据name拿到所有checkbox
    function getCheckBoxByName(name) {
    var arr = [];
    Ext.form.CheckboxManager.getByName(name).each(function(cb) {
    arr.push(cb)
    });
           alert(arr.length)
    }
      

  6.   

    'checkboxfield'这个是ext4.0么?
    我感觉应该这样
      xtype      : 'checkboxgroup', 
                fieldLabel : 'Toppings', 
               // defaultType: 'checkboxfield', 
                items: [ 
    ]