2

我有商店,我用这段代码添加了一条新记录。首先它添加新记录,然后同步到后端。

Ext.getStore('ilhan').add(Ext.getCmp('contacForm').getValues());
Ext.getStore('ilhan').sync({
    success: function(){
        Ext.getStore('ilhan').load();
        Ext.getCmp('customerWindow').close();
    }
});

我也可以使用下面的代码删除记录。

Ext.getStore('ilhan').remove(Ext.getCmp('theGrid').getSelectionModel().getSelection()[0]);
Ext.getStore('ilhan').sync({
    success: function(){
        Ext.getStore('ilhan').load();
    }
});

但我不知道如何更新记录。我只能用网格行中的数据填写表格。

Ext.getCmp('contacEditForm').getForm().setValues(Ext.getCmp('theGrid').getSelectionModel().getSelection()[0].data);

那么,我有add存储remove方法,但我没有任何update方法?我应该如何更新商店?

4

3 回答 3

3

我建议使用Model

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: ['id', 'name', 'email'],

    proxy: {
        type: 'rest',
        url : '/users'
    }
});

创造:

var user = Ext.create('User', {name: 'Ed Spencer', email: 'ed@sencha.com'});

user.save(); //POST /users

加载:

//Uses the configured RestProxy to make a GET request to /users/123
User.load(123, {
    success: function(user) {
        console.log(user.getId()); //logs 123
    }
});

更新:

//the user Model we loaded in the last snippet:
user.set('name', 'Edward Spencer');

//tells the Proxy to save the Model. In this case it will perform a PUT request to /users/123 as this Model already has an id
user.save({
    success: function() {
        console.log('The User was updated');
    }
});

删除:

//tells the Proxy to destroy the Model. Performs a DELETE request to /users/123
user.erase({
    success: function() {
        console.log('The User was destroyed!');
    }
});
于 2015-04-14T16:16:47.343 回答
2

更新。

var form = Ext.getCmp('contacForm'),
    record = form.getRecord(),
    values = form.getValues(),
    store = Ext.getStore('ilhan');
record.set(values);
store.sync({
    success:function() {
        store.load()
    }
});
于 2015-03-26T05:12:58.813 回答
1

看看你的记录。查看“脏”属性是否为真。这就是代理用来确定记录是帖子还是看跌期权的方法。

于 2015-03-26T00:12:46.700 回答