【问题标题】:How to access JS-Object elements with getSelectedRecords()-function provided by Syncfusion如何使用 Syncfusion 提供的 getSelectedRecords() 函数访问 JS-Object 元素
【发布时间】:2019-02-26 13:47:51
【问题描述】:

我是这个平台的新手。我感谢任何形式的回答,如果我弄错了或违反了本平台的任何规则,请随时指出。

我使用 Angular-Framework(7. 版本)和 syncfusion 来构建 Web 应用程序。我通过 API 和 Syncfusion 提供的功能接收数据,我可以访问(表的)行的索引及其记录。

所以,我想知道您是否可以通过使用 Syncfusion 提供的 getSelectedRecords 函数来获取 JS-Object 的元素(其值)。

遗憾的是,我不在我编码的环境中,但我问自己如何做到这一点,如果它真的可能的话。

于是我搜索了一个Syncfusion官方文档的示例代码,如下所示:

@Component({
    selector: 'app-container',
    template: <ejs-grid #grid [dataSource]='data' height='315px' 
(rowSelected)='rowSelected($event)'>
                <e-columns>
                    <e-column field='OrderID' headerText='Order ID' 
textAlign='Right' width=120></e-column>
                    <e-column field='CustomerID' headerText='Customer ID' 
width=150></e-column>
                    <e-column field='ShipCity' headerText='Ship City' 
width=150></e-column>
                    <e-column field='ShipName' headerText='Ship Name' 
width=150></e-column>
                </e-columns>
               </ejs-grid>
})
export class AppComponent implements OnInit {

public data: Object[];

@ViewChild('grid')
public grid: GridComponent;

ngOnInit(): void {
    this.data = data;
}

rowSelected(args: RowSelectEventArgs) {
    let selectedrowindex: number[] = this.grid.getSelectedRowIndexes();  // Get the selected row indexes.
    alert(selectedrowindex); // To alert the selected row indexes.
    let selectedrecords: Object[] = this.grid.getSelectedRecords();  // Get the selected records.
}
} 

在函数 rowSelected 的最后一行,您可以看到 Object 的 Records 存储在 Object[] 类型中。使用 console.log 函数,我看到记录也存储在一个对象中,并且对象是可访问的。除了使用 getSelectedRecords() 并将其存储在一个对象中,我可以扩展该函数以访问该对象并获取一个元素或者更确切地说它的值并将其存储在一个具有元素类型的变量中吗?

在函数后面加上“.”并将元素名称写在一边this.grid.getSelectedRecords().elementsname 将不起作用,但有类似的东西吗?

我希望我清楚地解释了我的问题。如果有什么不清楚的,请询问。

【问题讨论】:

    标签: angular typescript syncfusion


    【解决方案1】:

    你可以通过this.grid.selectionModule.selectedRecords属性获取选中的行元素,你可以通过如下的选中行索引来获取选中记录的特定值。

    rowSelected(args:rowSelectedEventArgs){      
          let selectedRowIndex: number[] = this.grid.getSelectedRowIndexes();
          let selectedRowEle: number = (this.grid.getSelectedRecords()[0] as any).OrderID // Get the selected record value using "getSelectedRecords()" 
          let selectedRowElement: Element[] = this.grid.selectionModule.selectedRecords;    // Get the Selected record row element collection.  
        }
    

    请参阅sample 了解更多信息。

    如果您需要进一步的帮助,请与我们联系。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-22
      • 2013-12-24
      • 2010-09-28
      • 2021-12-14
      相关资源
      最近更新 更多