简体   繁体   中英

Get all records from a selected row - Extjs

So I have the controller here to return records of a clicked row:

...
this.control({
             'mylist': {
                cellclick: function(view, td, cellIndex, record, tr, rowIndex, e, eOpts) {
                        var id = record.get('ID');
                        var name = record.get('NAME');
                        var desc = record.get('DESC');
                        var view = record.get('VIEW');
...

How can I instead iterate through mylist dynamically to get all the fields and assign a variable to each field(as the number of columns may increase in the future)?

Cheers!

If you are looking to loop through only the fields of the record that are mapped to defined columns you could do the following:

cellclick: function(view, td, cellIndex, record, tr, rowIndex, e, eOpts) {

  var i,
      columns = view.panel.columns, 
      currentRecordKey,
      newRecord = {};

   for(i=0; i < columns.length; i++){

        currentRecordKey = columns[i].dataIndex;
        newRecord[currentRecordKey] = record.get(currentRecordKey)
   }

   //do something with new record
}

While this solution does not create a var for ever key it does create a map containing all values of the current record which serves a similar purpose. For example, you could simply use newRecord.id to get the id field for the record in your example and it would serve the same purpose as a var declaration because the statement would fail if that field (key in the map) didn't actually exist. Keep in mind that this is not much different than simply using the actual record itself minus some of the extra fields from the record object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM