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 badges
Add a ment  | 

3 Answers 3

Reset to default 4

Ext.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