2012-10-02 31 views
2

大量的谷歌搜索和调试后,我无法弄清楚为什么我在我的模型实例中使用UUID策略时出现错误。设置UUID策略抛出我一个错误

我正在使用localStorage在用户的设备上存储远程数据,ST2推荐(他们说“你需要”)在我的模型实例中使用UUID标识符来生成唯一ID。

如果我不这样做,我得到:

[WARN][Anonymous] Your identifier generation strategy for the model does not ensure unique id's. Please use the UUID strategy, or implement your own identifier strategy with the flag isUnique. 

如果我这样做,我得到

Uncaught TypeError: Cannot call method 'substring' of undefined 

这里是我的模型:

Ext.define("MyApp.model.News", { 
    extend: 'Ext.data.Model', 

    config : { 
     idProperty: "localId", 
     identifier: { 
      type: 'uuid' 
     }, 
     fields : [ { 
      name: "localId", 
      type: "auto" 
     },{ 
      name : "id", 
      type : "integer" 
     }, { 
      name : "title", 
      type : "string" 
     }[...]], 
     proxy: { 
      type: 'localstorage', 
      id : 'proxyNews' 
     } 

    } 
}); 

而localStorage的店:

Ext.define('MyApp.store.NewsLocalStorage', { 
    extend: "Ext.data.Store", 
    config: { 
     storeId: 'newsLocalStorage', 
     model: "Lmde.model.News", 
     autoLoad: true 
    } 
}); 

我错过了什么?

+0

模型的任何想法或线索? – Yoksy

回答

0

嗯,我只将模型添加到应用程序,它的工作原理。 (我猜LMDE = MyApp来)

我添加到启动:

MyApp.News = Ext.create('MyApp.model.News'); 

这里再次

Ext.define("MyApp.model.News", { 
    extend: 'Ext.data.Model', 

    config: { 
     idProperty: "localId", 
     identifier: { type: 'uuid' }, 
     fields: [ 
      { name: "localId", type: "auto" }, 
      { name: "id", type: "integer" }, 
      { name: "title", type: "string" } 
     ], 
     proxy: { type: 'localstorage', id: 'myapp.news' } 
    } 
});