具有新记录的Store.sync()不会导入服务器生成的字段作为响应 [英] Store.sync() with new record does not import server-generated fields in response

查看:126
本文介绍了具有新记录的Store.sync()不会导入服务器生成的字段作为响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个启用行编辑的网格。当我添加一行并调用store.sync()时,服务器会在该记录上生成某些字段,并在响应中返回完整的记录信息。但是,除了id之外,ExtJS似乎没有更新其记录的副本。有没有办法做到这一点,还是需要编写自定义代码?



这是网格控制器的摘录:

  doneEdit:function(editor,e,eOpts){

var me = this;

//
//在更新期间设置加载掩码(如果记录更改并有效)
//
if(e.record.dirty& ;& e.record.isValid()){
e.grid.showUpdatingMask(); (

e.store.sync
}
else {
me.cancelEdit(editor,e,eOpts);
}
$,

//
// onSaveSuccess()仅用于行编辑器网格
//
onSaveSuccess:function (批次,选项){

var me = this,
grid = me.getGrid();

grid.getStore()。filter([]); //重新运行任何已存在的过滤器,并进行排序。

grid.hideMask();

//更新只读活动存储,如果由子类指定
if(me.activeStore){
// $ TODO:handle load failure
me .activeStore.load();
}
},


解决方案

我有同样的问题(Ext 4.2.1)。原因是我忘了设置idProperty在读者默认是id,我的是_id。 Ext无法更新记录,因为它无法识别匹配的ID。现在它的作用就像一个魅力。



所以确保响应是读者期望的正确格式(根,idProperty,模型定义,...) p>

I have a grid with row-editing enabled. When I add a row and call store.sync(), the server generates certain fields on that record, and returns the full record info in the response. However, ExtJS does not seem to update its copy of the record, except for the id. Is there a way to make it do that, or do I need to write custom code?

This is an excerpt of the grid's controller:

doneEdit: function (editor, e, eOpts) {

    var me = this;

    //
    // Set up loading mask on grid during update (if record changed and is valid)
    //
    if (e.record.dirty && e.record.isValid()) {
        e.grid.showUpdatingMask();

        e.store.sync({
            success: me.onSaveSuccess,
            failure: me.onSaveFailure,
            scope: me
        });
    }
    else {
        me.cancelEdit(editor, e, eOpts);
    }
},

//
// onSaveSuccess() is only used for row editor grids
//
onSaveSuccess: function (batch, options) {

    var me = this,
        grid = me.getGrid();

    grid.getStore().filter([]); // re-run whatever filters already exist, and sort.

    grid.hideMask();

    // update read-only active store if specified by sub-class
    if(me.activeStore) {
        // $TODO: handle load failure
        me.activeStore.load();
    }
},

解决方案

I had the same problem (Ext 4.2.1). The reason was that I forgot to set the idProperty on the reader default is "id", mine is "_id". Ext silently failed to update the record because it didn't recognize a matching id. Now it works like a charm.

So make sure the response is in the correct format expected by your reader (root, idProperty, model definition, ...)

这篇关于具有新记录的Store.sync()不会导入服务器生成的字段作为响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆