简体   繁体   English

从选定的行中获取所有记录-Extjs

[英]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)? 我该如何动态遍历mylistget所有字段并为每个字段分配一个变量(因为将来列的数量可能会增加)?

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. 虽然此解决方案不会为每个键创建var ,但会创建一个包含当前记录的所有值的映射,该映射具有相似的用途。 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. 例如,您可以简单地使用newRecord.id来获取示例中记录的id字段,它的作用与var声明相同,因为如果该字段(地图中的键)实际上没有声明,则该语句将失败存在。 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. 请记住,这与仅使用实际记录本身减去记录对象中的一些额外字段没有太大区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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