首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

GWT EXT的STORE的add步骤

2012-09-15 
GWT EXT的STORE的add方法store的add方法要求加入的record的id不相同,否则不会被加入。见ext-all-debug.js的

GWT EXT的STORE的add方法
store的add方法要求加入的record的id不相同,否则不会被加入。

见ext-all-debug.js的Ext.util.MixedCollection,其add方法为:
add : function(key, o){
        if(arguments.length == 1){
            o = arguments[0];
            key = this.getKey(o);
        }
        if(typeof key == "undefined" || key === null){
            this.length++;
            this.items.push(o);
            this.keys.push(null);
        }else{
            var old = this.map[key];
            if(old){
                return this.replace(key, o);
            }
            this.length++;
            this.items.push(o);
            this.map[key] = o;
            this.keys.push(key);
        }
        this.fireEvent("add", this.length-1, o, key);
        return o;
    },
getKey : function(o){
         return o.id;
    },
如果发现有相同的id,则就会被return this.replace(key, o);掉。

可以用Ext.generateId()方法随机生成新的id

热点排行