admin管理员组文章数量:1391947
I want to allow users to create new records and edit existing records from the same form in ExtJS 4. I am working with ExtJS 4.0.7.
It's easy for me to load a record.
var form = Ext.ComponentQuery.query('#myForm');
form.loadRecord(record);
But if I want to start fresh, there is no way to unload it! At least, no proper way that I can find. I've already researched for hours, and even looked through some of the core Ext code for an answer. The best I could e up with to "unload" a record is:
form._record = null;
If I don't explicitly declare _record
as null
, Ext will always try to update the record stored there. form.reset();
does not clear the loaded record either.
Is there a "proper" way to clear the record tied to a form so that a new record can be saved?
I want to allow users to create new records and edit existing records from the same form in ExtJS 4. I am working with ExtJS 4.0.7.
It's easy for me to load a record.
var form = Ext.ComponentQuery.query('#myForm');
form.loadRecord(record);
But if I want to start fresh, there is no way to unload it! At least, no proper way that I can find. I've already researched for hours, and even looked through some of the core Ext code for an answer. The best I could e up with to "unload" a record is:
form._record = null;
If I don't explicitly declare _record
as null
, Ext will always try to update the record stored there. form.reset();
does not clear the loaded record either.
Is there a "proper" way to clear the record tied to a form so that a new record can be saved?
Share Improve this question asked Nov 3, 2011 at 19:55 John KrullJohn Krull 3024 silver badges14 bronze badges3 Answers
Reset to default 4Ext.form.Panel
is derived from Ext.form.Basic
, where _record exists as a private variable. And if you take a look into the code of Ext.form.Basic
http://docs.sencha./ext-js/4-0/source/Basic.html#Ext-form-Basic-method-getRecord
you'll note that there is no clear method for _record. reset
method just do reset of form fields.
So you're doing right when setting form._record = null;
Personally, I'd prefer to do delete form._record
, but your approach should work either.
The docs describe that the reset
method's optional first parameter to true unbinds any record set by loadRecord. So in Ext 4 and 5 you can just do:
yourForm.reset(true);
Internally it does:
delete me._record;
I would try making a blank record and loading that to clear the form and record.
var blankRecord = Ext.create('YourModel');
yourForm.loadRecord(blankRecord);
本文标签: javascriptWhat is the proper way to unloadunbind a record from a form in ExtJS 4Stack Overflow
版权声明:本文标题:javascript - What is the proper way to unloadunbind a record from a form in ExtJS 4? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744767483a2624129.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论