Is there any way to disable “idProperty” of Model in Extjs?

偶尔善良 提交于 2019-12-02 08:43:19

问题


I have a simple Model/proxy. When I create a object of model to send to server via REST, ExtJs is generating Id and putting its value in my "id" field and that is conflicting with my data. Is there any way to stop this behavior or to solve this issue?
I have read idProperty Sencha Docs but I am not able to solve my issue. Kindly Help.


回答1:


I ran into same problem and using ajokn answer I did this.

Ext.define('ThemeApp.model.peopleModel', {
    extend: 'Ext.data.Model',

    fields: [ 
        {name: 'id', type: 'int', persist: false},
        {name: 'xyz', type: 'auto'}
    ]
}

I didn't set the idProperty : 'login' cause its default value is 'id', so simply set persist: false for id property in your model.




回答2:


Set config options: persist: false.

Ext.define('User', {
    extend: 'Ext.data.Model',
    idProperty : 'login'
    fields: [
        {name: 'login', type: 'string', persist: false},
        {name: 'username', type: 'string'},
        {name: 'password', type: 'string'}
    ]
});



回答3:


Set the idProperty to a non existing field. Its dirty I know, but this should do it.

Ext.define('User', {
    extend: 'Ext.data.Model',
    idProperty : 'foo'
});


来源:https://stackoverflow.com/questions/29562263/is-there-any-way-to-disable-idproperty-of-model-in-extjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!