【问题标题】:Data table issue - ERROR TypeError: val.slice is not a function数据表问题 - ERROR TypeError: val.slice is not a function
【发布时间】:2017-08-02 06:10:50
【问题描述】:

错误类型错误:

val.slice 不是函数

数据表配置

$.p-dataTable #dt [value]="customers" [(selection)]="chkBoxSelect" 
 dataKey="customerId" [rows]="10" [paginator]="true" 
 paginatorPosition="both" [pageLinks]="5" [rowsPerPageOptions]="[5,10,20]" 
 [globalFilter]="gb" [headerCheckboxToggleAllPages]="false" 
 [editable]="true" exportFilename="customers" [lazy]="true" 
 [totalRecords]="totalRecords" onLazyLoad)="loadCustomersByPage($event)"

回调函数

$loadCustomersByPage(event: LazyLoadEvent) {

    const parameters = "?page=" + event.first + "&size=" + (event.first + event.rows);

     this._cs.findAllActiveCustomerDetailsByPage(parameters).subscribe(
       (data: any) => {
         this.customers = data;
       },
       (error) => {
          console.log("--error--" + error)
       }
  );
}

【问题讨论】:

  • 我的问题解决了。这是我的错。数据不是正确的对象
  • 能否提供正确的对象类型?

标签: angular primeng primeng-datatable


【解决方案1】:

看起来数据格式不正确..

这是分配给表格的数据对象的样子:

let cars = [
   {"brand": "VW", "year": 2012, "color": "Orange", "vin": "dsad231ff"},
   {"brand": "Audi", "year": 2011, "color": "Black", "vin": "gwregre345"},
   {"brand": "Renault", "year": 2005, "color": "Gray", "vin": "h354htr"},
   {"brand": "BMW", "year": 2003, "color": "Blue", "vin": "j6w54qgh"},
   {"brand": "Mercedes", "year": 1995, "color": "Orange", "vin": "hrtwy34"},
   {"brand": "Volvo", "year": 2005, "color": "Black", "vin": "jejtyj"},
   {"brand": "Honda", "year": 2012, "color": "Yellow", "vin": "g43gr"},
   {"brand": "Jaguar", "year": 2013, "color": "Orange", "vin": "greg34"},
   {"brand": "Ford", "year": 2000, "color": "Black", "vin": "h54hw5"},
   {"brand": "Fiat", "year": 2013, "color": "Red", "vin": "245t2s"}
]

【讨论】:

    【解决方案2】:

    如果您需要 JSON 格式的数据,请包含 .json() 方法:

     this._cs.findAllActiveCustomerDetailsByPage(parameters).subscribe(
           (data: any) => {
             this.customers = data.json();
           },`enter code here`
    

    【讨论】:

      猜你喜欢
      • 2018-05-09
      • 2017-08-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-20
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多