如何在存储加载时启用布尔字段的基于复选框的值,而不在Ext.selection.CheckboxModel中触发侦听器

时间:2014-04-30 06:57:56

标签: extjs checkbox

我是EXTJS的新手。我有一个带有复选框的网格,并且将根据模型中的布尔字段选中或取消选中该复选框。我有这个监听器,它在加载商店时执行此操作。这是以下代码。

listeners: {
    afterrender: function(obj)
       {                    
            var store = THIS.GridStore;
                var model = THIS.GridView.selModel;
            model.suspendEvents();
            store.load(
                {
            scope : this,
                params : {
                 method : 'getData',
                 eventId : 'nativemethodcall',
                 subEventId : ''
                  },
                 callback: function(records, operation, success)
                 {
                model.suspendEvents();
                    var count = store.getTotalCount();
                for (var i = 0; i < count; i++) {
                       var record = store.getAt(i);
                       if(record != undefined)
                        {
                        if (record.get('analyticsEnabled') == true) {
                                model.selectRange(i, i, true);
                                            }
                          }
                  }
                  model.resumeEvents();
              }
         });
     }
}

在呈现UI之后,我在复选框选择模型中有侦听器,当用户选中或取消选中复选框并分别更新模型时,将调用该模型。代码

selModel : Ext.create('Ext.selection.CheckboxModel',
                            {

                                listeners :
                                {

                                    deselect: function(model, record, index)
                                    alert('deselect called');
                                    {
                                        var store = THIS. GridStore;
                                        var record = store.getAt(index);
                                        record.set("Enabled", false);
                                        THIS.GridView.refresh();
                                    },
                                    select: function(model, record, index)
                                    {
                                    alert('select called');
                                        var store = THIS. GridStore;
                                        var record = store.getAt(index);
                                        record.set("Enabled", true);
                                        THIS.GridView.refresh();
                                    },
                                    selectionchange: function(model, selected, eOpts)
                                    {
                                        alert('selection called');
                                        var count = THIS. Store.getTotalCount();
                                        var selcount = selected.length;
                                        if (selcount == 0)
                                        {
                                            model.deselectAll(true);
                                            var store = THIS. GridStore;
                                            var count = store.getTotalCount();
                                            for (var i = 0; i < count; i++) {
                                                var record = store.getAt(i);
                                                if (record.get('Enabled') == true)
                                                {
                                                    record.set("Enabled", false);
                                                }
                                            }
                                            THIS.GridView.refresh();
                                        } else if (selcount == count)
                                        {
                                            model.selectAll(true);
                                            var store = THIS. GridStore;
                                            var count = store.getTotalCount();
                                            for (var i = 0; i < count; i++)
                                            {
                                                var record = store.getAt(i);
                                                if (record.get('Enabled') == false)
                                                {
                                                    record.set("Enabled", true);
                                                }
                                            }
                                            THIS. GridView.refresh();
                                        }

                                    }
                                }
                            }),

我面临的问题是,当回调函数在商店加载期间检查复选框时,会调用选择复选框模型侦听器(选择和选择更改)函数。我已暂停像这样的模特活动        var model = THIS.GridView.selModel;       model.suspendEvents();  在回电期间,但似乎没有用。请帮忙。

1 个答案:

答案 0 :(得分:0)

你可以使用checkColumn和cellModel,而不是使用checkboxSelection模型。