使用CheckboxSelectionModel从网格中删除多个项目

时间:2013-01-14 22:21:15

标签: extjs grid extjs4 sencha-architect selectionmodel

在Sencha Architect上使用ExtJs4.1。

我的onDeleteButton代码中有以下代码

onDeleteButtonClick: function(button, e, options) {
     var active = this.activeRecord;
     var myGrid = Ext.getCmp('publisherResultsGridView'),
         sm = myGrid.getSelectionModel(),
         selection = sm.getSelection(); // gives you a array of records(models)

     if (selection.length > 0){
            for( var i = 0; i < selection.length; i++) {
                            this.application.log('OnDeleteItemID is ' + selection);
            }
            this.remove(selection);
     }

Remove功能代码

remove: function(record) {
        var store = Ext.getStore('PublisherProperties');
        store.proxy.url = MasterDataManager.globals.url + "Publishers/";
        store.remove(record);
        store.sync();

当我运行它时,我可以在我的日志中看到一个对象数组,在执行remove函数后我也没有得到任何错误。但商店没有更新,我的意思是它不会删除所选项目。

请有人帮助我。

由于

1 个答案:

答案 0 :(得分:1)

我通过进行以下更改解决了我的问题。

onDeleteButtonClick

if (selection.length > 0){
                for( var i = 0; i < selection.length; i++) {
                                this.application.log('OnDeleteItemID is ' + selection[i].data.id);
                                this.remove(selection[i]);
                }

         }

Remove功能

remove: function(record) {
    var store = Ext.getStore('PublisherProperties');
    this.application.log('Remove Function is ' + record);
    store.proxy.url = MasterDataManager.globals.url + "Publishers/" + record.data.id;
    store.load({
                        scope : this,
                        callback : function(records, operation, success){
                            if (records.length > 0){
                                var store2 = Ext.getStore('PublisherProperties');
                                        store2.proxy.url = MasterDataManager.globals.url + "Publishers/";
                                        store2.remove(records[0]);
                                        store2.sync();
                             }
                        }
            });
    //store.remove(record);
    //store.sync();