首先增加一条数据,然后alert(categoryStore.getModifiedRecords());//结果是'' 空
var data = {'categoryName':newCategory};
var record = new categoryStore.recordType(data);
categoryStore.insert(index,record);
------------------------------------------------------------
然后修改store的数据
categoryStore.getAt(index).set('categoryName',text);
alert(categoryStore.getModifiedRecords().length);//有长度,不为空了
------------------------------------------------------------
最后删除一条记录 再alert下长度还是原来的长度不变
categoryStore.remove(categoryStore.getAt(categoryId));
------------------------------------------------------------
问题:getModifiedRecords 在api上不是说(不包括被删除的记录),为什么我删除条记录后长度还是一样、
还有store新增的数据也不再getModifiedRecords的范围内?

解决方案 »

  1.   

    你还需要在store添加一个属性pruneModifiedRecords:true 
    具体情况请看api,我也是查看源码才知道,如果不设置这个属性modifyRecords将不根据我们的意愿工作。
      

  2.   

    请在store中添加 pruneModifiedRecords:true 属性,这样modifyRecord才正常工作,我也是看了源码才知道有这个属性,具体可以看api,建议不要看中文API
      

  3.   

    请在store中添加 pruneModifiedRecords:true 属性,这样modifyRecord才正常工作,我也是看了源码才知道有这个属性,具体可以看api,建议不要看中文API
      

  4.   

    好像只有这句话:categoryStore.getAt(index).set('categoryName',text); 
    getModifiedRecords才有效果,删除,新增都没效果 :(
      

  5.   

    是啊,添加了那个属性之后 删除新增就有效果了
    贴个源码给你看看
    //removeAt 源码
    removeAt : function(index){
            this.remove(this.getAt(index));
        },
    //removeAt调用remove
    remove : function(record){
            if(Ext.isArray(record)){
                Ext.each(record, function(r){
                    this.remove(r);
                }, this);
                return;
            }
            var index = this.data.indexOf(record);
            if(index > -1){
                record.join(null);
                this.data.removeAt(index);
            }
            if(this.pruneModifiedRecords){
                this.modified.remove(record);
            }

            if(this.snapshot){
                this.snapshot.remove(record);
            }
            if(index > -1){
                this.fireEvent('remove', this, record, index);
            }
        },
      

  6.   

    我在store里设置pruneModifiedRecords:true,了,可还是不行
      

  7.   

    刚刚又看了下源码,如果了用的是Ext.data.Store,需要设置writer属性,设置writer属性之后 prounModifyRecords就会被自动设置成true,而新增record就会被添加到modifyrecord里面的。建议了用JsonStore,因为他的writer属性默认就是JsonWriter,而store里面的writer属性默认是undifined
      

  8.   

    你好,这我store的配置
    categoryStore = new Ext.data.JsonStore({
    url:'../main/article!findCategory.action',
    root:'acList',
    fields:[{
    name:'categoryName',
    mapping:'name'
    }]
    });
    ----------------------------------------------------------------
    //删除的方法
    function removeCategory(categoryId){
    categoryStore.remove(categoryStore.getAt(categoryId));
    doLayOut();
    alert(categoryStore.getModifiedRecords());//还是''
    }
      

  9.   

    alert(categoryStore.getModifiedRecords());//还是''
    是这样的,remove一个record,在ModifiedRecord里面也会把它删除。
    新增和修改的record在modifiedRecord里面有记录,删除的数据没有。建议用一个全局变量记录下删除的record的id,然后提交到服务器处理。