设置 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'
        }
    }
});

和本地存储存储:

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

我错过了什么?

,我只将模型添加到应用程序中,它可以工作。(我猜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' }
    }
});

相关内容

最新更新