gpt4 book ai didi

javascript - Sencha Architect 本地存储不工作

转载 作者:行者123 更新时间:2023-12-02 18:17:24 25 4
gpt4 key购买 nike

我是 Sencha Touch/Architect 的新手,正在尝试创建我的第一家商店。我有以下项目设置:

商店

Ext.define('InkStudio.store.MyStore', {
extend: 'Ext.data.Store',

requires: [
'InkStudio.model.activityLog'
],

config: {
data: {
entryID: 1,
name: 'First',
event: 'First event'
},
model: 'InkStudio.model.activityLog',
storeId: 'MyStore',
proxy: {
type: 'localstorage',
uniqueID: 'entryID'
}
}
});

型号

    Ext.define('InkStudio.model.activityLog', {
extend: 'Ext.data.Model',

config: {
identifier: 'uuid',
fields: [
{
name: 'entryID',
type: 'auto'
},
{
name: 'name',
type: 'string'
},
{
name: 'event',
type: 'string'
}
]
}
});

然后我有一个带有以下内容的按钮进行测试。该按钮正在工作,我收到了两条“成功”消息,但当我查看它或查找文件时,数据实际上从未显示在商店中。

var store=Ext.getStore('MyStore');
if(store.add({name: "KITTY", event: "Clicked on the register"})){
console.log("Successfully added");
}else{
console.log("Failed to add");
}
if(store.sync()){
console.log("Successfully synced");
}else
{
console.log("Failed to sync");
}

我还漏掉了什么吗?

最佳答案

仅当您希望在 View 中显示固定信息时才使用data配置。正确的是:

Ext.define('InkStudio.store.MyStore', {
extend: 'Ext.data.Store',

requires: [
'InkStudio.model.activityLog'
],

config: {
model: 'InkStudio.model.activityLog',
storeId: 'MyStore',
proxy: {
type: 'localstorage',
id: 'my-store-id'
}
}
});

编辑存储方法是异步的,因此您需要使用选项来实际查看更改。

var record = Ext.create('InkStudio.model.activityLog');
...
//first we load our store.
store.load({
callback: function(records, operation, success) {
console.log('Store loaded...');
//then we can add records
store.add(record);
store.sync({
success: function(batch, options) {
console.log("Record saved...");
},
failure : function(batch, options) {
console.log("Error!");
}
});
}
});

关于javascript - Sencha Architect 本地存储不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19164110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com