【问题标题】:how to get Extjs Store last insert id?如何获取 Extjs Store 最后插入 id?
【发布时间】:2014-11-20 00:46:42
【问题描述】:

我使用休息代理,我想知道最后一个插入记录的最后一个“id”,我的服务器端应该是这样的:

保存前:

id:-1

保存:

var values = this.getFrmReciept().getValues();
var record = this.getFrmReciept().getRecord();
var store  = Ext.getStore('recStore');
record.set(values);
record.save();
store.add(record);
alert(record.data.id);//result is '-1'

从服务器响应:

{"success":true,"reciept":[{"id":"366","c_id":"57","crdt_auth":"test","typ":"2","clerk_id":"1"}]}

保存后我使用相同的记录来获取新的'id':

alert(record.data.id);//result is '-1'

如何获取从服务器返回的新 'id'?

谢谢你的建议

【问题讨论】:

    标签: extjs


    【解决方案1】:
    var newId = -1;
    
    record.save({
        success: function (rec, op) {
            newId = rec.getId();
            alert(newId);
        }
    });
    

    Look fiddle example

    【讨论】:

      【解决方案2】:

      save 方法是异步调用的。因此,您需要将回调传递给将在收到服务器响应后调用的 save 方法

      record.save({
          callback : function (record, operation, success) {
              if (success) {
                  alert(record.getId()); // should be 366
              }
          }
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-11-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多