How to set multiple values ​​at a time in Ext.data.Model?

In the Ext.data.Model class Ext.data.Model we have a set(fieldName, newValue) method that sets one model field to a given value.

How to set several values ​​at once? Something like:

 Ext.data.Model.set({ field1: 'value1', field2: 345, field3: true }); 
+7
source share
5 answers

This is not possible, but according to my understanding, you only want to combine these different calls to set the value in the model, when you need to notify about changes in the model only once for storage, so the repository will only fire the update event once

If so, you can use beginEdit and endEdit

 var model = new Ext.data.Model(); model.beginEdit(); model.set('field1', 'value1'); model.set('field2', 345); model.set('field3', true); model.endEdit(); 
+7
source

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Model

You can set a field for installation or an object containing key / value pairs

 record.set({ field1: value, field2: value2 }); // or record.set(field1, value); record.set(field2, value2); 
+9
source

Can't you do this only with Ext.create() ? As explained here:

http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.ModelManager-method-create

0
source

I'm late to the party, but here's another way to do this:

 var rec = new Ext.data.Model({ field1: 'value1', field2: 'value2', field3: 'value3' }); 
0
source

Just create a new record that returns an empty record with all the fields of the model.

 //this one is for the grid model var blank_record = Ext.create(grid.store.model); 

Create an object to set new values ​​in the fields

  var new_record = { 'field1':'value1', 'field2':'value2', 'field3':'value3' }; 

then set the values ​​of the objects to an empty record

  blank_record.set(new_record); 

Next, if you want to add a newly created record to the grid

 grid.store.add(blank_record); 

Hope this helps

0
source

All Articles