Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在ExtJS中使用表单更新存储?_Javascript_Extjs_Extjs5_Extjs Stores - Fatal编程技术网

Javascript 如何在ExtJS中使用表单更新存储?

Javascript 如何在ExtJS中使用表单更新存储?,javascript,extjs,extjs5,extjs-stores,Javascript,Extjs,Extjs5,Extjs Stores,我有一个存储,我用这个代码添加了一个新记录。它首先添加新记录,然后与后端同步 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').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
方法?我该如何更新商店?

看看你的记录。查看“dirty”属性是否为true。这就是代理用来确定记录是post还是put的方法。

查看您的记录。查看“dirty”属性是否为true。这就是代理用来确定记录是post还是put的内容。

更新

var form = Ext.getCmp('contacForm'),
    record = form.getRecord(),
    values = form.getValues(),
    store = Ext.getStore('ilhan');
record.set(values);
store.sync({
    success:function() {
        store.load()
    }
});
更新

var form = Ext.getCmp('contacForm'),
    record = form.getRecord(),
    values = form.getValues(),
    store = Ext.getStore('ilhan');
record.set(values);
store.sync({
    success:function() {
        store.load()
    }
});
我建议使用

创建:

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

user.save(); //POST /users
负载:

更新:

//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!');
    }
});
我建议使用

创建:

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

user.save(); //POST /users
负载:

更新:

//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!');
    }
});