2012-05-09 210 views
1

我被困在一种情况,在这种情况下,我必须'检查'位于工具栏中的复选框'检查'列表中存在的所有复选框。如何'检查'列表中的所有复选框'检查'单个复选框?

这里的代码来创建复选框列表: -

itemTpl: '<input type="checkbox" name="box" enabled="enabled" value="open" 
name="comment_status" id="status" <tpl if="active">checked="checked"</tpl> /> 
{groupName}{#}', 

这里是我的复选框代码: -

var checkBox = { 
      xtype: 'checkboxfield', 
       name : 'all', 
      // label: 'All', 
       itemId: 'all', 
       value: 'all', 
       lableWidth: "0", 
       width: 1, 
       padding: '0 0 15 30', 
       checked: false, 
       listeners: { 
        check:function() { 
        // alert("check"); 

         item = Ext.get("status"); 
         console.log("item:-"+Ext.JSON.encode(item)); 

         chkBox = item.down('input').dom; 

         var checkboxes = Ext.getStore('group'); 
         console.log(checkboxes.getCount()); 

         for(var i=0;i<checkboxes.getCount();i++){ 
         chkBox.checked = true; 
         } 

        }, 
        uncheck:function(){ 
        // alert("uncheck"); 
        } 
       } 
     }; 

在上述复选框检查,我想,在“itemTpl”中定义的所有复选框会检查,反之亦然。我知道我的代码在检查:function(){}是没有那么好,解决了我的问题(两个代码在不同的意见)。

所以,请告诉我一些这个问题的解决方案。

Thanx提前。

+0

您有与您的复选框相关的模型吗? – Sephy

+0

是的,复选框列表有模型... – himanshu

+0

好吧,在任何情况下,你必须遍历你的列表存储,更改每个项目对应于复选框的布尔值为true,你应该完成。 – Sephy

回答

2

好的,我更新了your senchafiddle使它工作。 在物质,这里是我添加到您的代码:

添加2个功能列表控制器,到工具栏上的复选框管理措施:

checkAll:function(){ 
    this.getCheckboxList().getStore().each(function(record){record.set('active', true);}); 
}, 
uncheckAll:function(){ 
    this.getCheckboxList().getStore().each(function(record){record.set('active', false);}); 
} 

而且随着的复选框以添加工具栏统治他们(XD)以上列表:

{ 
     xtype : 'toolbar', 
     docked: 'top', 
     title: 'Check !', 
     items:[{ 
      xtype: 'checkboxfield', 
      name : 'all', 
      value: 'checkAll', 
      listeners:{ 
       check:function(){ 
        MyApp.app.getController('MainViewController').checkAll(); 
       }, 
       uncheck:function(){ 
        MyApp.app.getController('MainViewController').uncheckAll(); 
       } 
      } 
     }] 
    } 

这将需要你做一些CSS来使ckeckbox不错,但行为是在这里。

+0

感谢名单乌拉圭回合的答案模式和列表的代码,但我已经用下面的代码 VAR项目= Ext.getStore的帮助(“组做了“); items.each(function(record){ record.set('active',true); }); 反正再次thanx为你的支持和你的方式由控制器做也是接缝一个好主意。 – himanshu

+1

是的,这是主意。更新您的商店会自动更新视图。使用每个元素是迭代商店所有元素的最简单方法。控制器的方式应该是ST2中正确的方法。虽然我的方式可以更清晰,在checkAll复选框上定义的ref和控制器上定义的控件! – Sephy