在本地存储数据 - 不起作用?

时间:2013-05-28 17:45:38

标签: extjs sencha-touch sencha-touch-2 sencha-architect

如你所见。如果我要更新一个FIELD,我会收到一个ALERT,它会显示我的模型TESTVALUE。第一次它是空的,我的商店将是空的。但第二次它应该显示我ROGER。但事实并非如此。这是我的商店从未同步过。

能有人帮我吗?

这是我的代码:

接收更新数据的控制器(已检查,确实接收事件)

Ext.define('Prototype.controller.MyController', {
extend: 'Ext.app.Controller',

config: {
    control: {
        "textfield": {
            change: 'onTextfieldChange'
        }
    }
},

onTextfieldChange: function(textfield, newValue, oldValue, eOpts) {
    Ext.getStore('localdb').load();
    var test = Ext.getStore('localdb').last().get('testValue');
    console.log(test);
    Ext.getStore('localdb').add({testvalue: 'ROGER'});
    Ext.getStore('localdb').sync();
}

});

型号:

Ext.define('Prototype.model.LocalData', {
extend: 'Ext.data.Model',

config: {
    identifier: {
        type: 'uuid'
    },
    proxy: {
        type: 'localstorage',
        id: 'test1'
    },
    fields: [
        {
            name: 'testValue'
        }
    ]
}
});

商店:

Ext.define('Prototype.store.LocalStore', {
extend: 'Ext.data.Store',

requires: [
    'Prototype.model.LocalData'
],

config: {
    model: 'Prototype.model.LocalData',
    storeId: 'localdb',
    syncRemovedRecords: false,
    proxy: {
        type: 'localstorage',
        id: 'test1'
    }
}
});

2 个答案:

答案 0 :(得分:1)

在执行同步之前,请将record.setDirty()添加到您的记录中。

答案 1 :(得分:0)

控制器应该是这样的

Ext.getStore('localdb').load();
var test = Ext.getStore('localdb').last().get('testValue');
console.log(test);
var tested = Ext.create('Prototype.model.LocalData');
tested.set('testValue','roger');
Ext.getStore('localdb').add(tested);
Ext.getStore('localdb').sync();

我没有正确地写出数据-_-'

相关问题