TAGS :Viewed: 10 - Published at: a few seconds ago

[ How to get a selected object within other stuff? ]

I have a multiselect grid where I can get schools.getSelectionModel().getSelection();

there is an object called data, I want to get a field within the data; lets say school_name

How I'll do it?

I've tried

schools.getSelectionModel().getSelection().data
schools.getSelectionModel().getSelection(data)     
schools.datagetSelectionModel().getSelection() 

they did not work.

Answer 1


You have to use Ext.each to iterate over the array of records..

Ext.each(schools.getSelectionModel().getSelection(), function(record, index, allRecords) {
    console.log(record.get('school_name');
});

Answer 2


This:

schools.getSelectionModel().getSelection()[0].get('school_name')

should give you a 'school_name' field from first row selected (which is also a first record in selection).

To iterate over all selected rows do:

var selectedSchools = schools.getSelectionModel().getSelection();
for (i in selectedSchools) {
  console.log(schools[i].get('school_name'));  //this will log school name to firebug console - you can do whatever you need
}