Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set multiple values at one time to Ext.data.Model?

Tags:

model

extjs

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

How to set multiple values at one time? Something like:

Ext.data.Model.set({
    field1: 'value1',
    field2: 345,
    field3: true
});
like image 871
s.webbandit Avatar asked Apr 28 '13 10:04

s.webbandit


3 Answers

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

You can set the field to set, or an object containing key/value pairs

record.set({
    field1: value,
    field2: value2
});

// or 

record.set(field1, value);
record.set(field2, value2);
like image 55
Dos Avatar answered Nov 15 '22 06:11

Dos


That's not possible, but as per my understanding you only want to merge this different calls for setting a value in model when you need to notify about changes in model only once to store so store will only fire update event once

If this is the case for you then you can use beginEdit and endEdit functions

var model = new Ext.data.Model();

model.beginEdit();

model.set('field1', 'value1');
model.set('field2', 345);
model.set('field3', true);

model.endEdit();
like image 39
Saket Patel Avatar answered Nov 15 '22 04:11

Saket Patel


Just create a new record which returns a blank record with all the model fields

//this one is for the grid model

var blank_record  = Ext.create(grid.store.model);

Create an object to set the new values to fields

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

then set the object values to the blank record

 blank_record.set(new_record);

Further if u want to add the newly created record to the grid

grid.store.add(blank_record);

Hope this helps

like image 25
Nishant Bajracharya Avatar answered Nov 15 '22 05:11

Nishant Bajracharya