2017-09-20 51 views
0

我嘗試建立自己的自定義數據網格,它的工作, 問題是執行任何操作,如不更新在angular4中執行操作後數據未更新?

my.component.html

<grid [data] = "data" [columns]="columns" 
    (actionChanged) = "onChangeAction($event)"> </grid> 

我刪除數據後。 component.ts

onChangeAction (actionData) { 
    console.log(actionData, 'action change data in main component') 
    if (actionData.action === 'delete') { 
      this.delete (actionData) 
    } 

    if (actionData.action === 'add') { 
     this.add (actionData) 
    } 
    } 
    delete (actionData) { 
    console.log(actionData, 'delete function calll', this.data.length) 
    const index: number = this.data.indexOf(actionData.rowData.name); 
    if (index === -1) { 
     this.data.splice(index, 1); 
    }; 
    console.log(this.data.length, index) 
    } 
    add (actionData) { 
    console.log(actionData, 'add function calll') 
    } 

** ** grid.ts

@Output() public actionChanged: EventEmitter<any> = new EventEmitter(); 

    public updateAction (row, action) { 
    console.log(row, 'Row', action) 
    let actionData = { 
      rowData: row, 
      action: action 
     } 
    this.actionChanged.emit(actionData); 
} 

我使用@input()從電網@outPUt()

我從電網到my.component完美,萬阿英,蔣達清獲取數據獲取數據將數據傳遞到網格執行刪除操作的數據後沒有更新到網格。

請任何人都可以幫助我。 在此先感謝

+0

確保你通過實施方法ngOnChanges – mareks

+0

是的,我試過onChanges,Docheck事件聽變化,與萬阿英,蔣達清解決50 %,數據在刪除操作後更新,但執行過濾器函數後數據未更新 – Rahiman

+0

如果@Input()屬性中發生任何更改,則grid.ts中的ngOnChanges()將偵聽更改。在你的主要組件中,onChangeAction()更新數據的值,只有那時ngOnChanges()纔會觸發,所以不要使用this.data.splice()來實現this.data = this.data.splice() – JayDeeEss

回答

0

您需要添加一個方法來grid.ts

ngOnChanges(changes: SimpleChanges) { 
    // changes holds the new data 
    // so you could set 
    // this.data = changes; 
} 
+0

這裏是什麼:SimpleChanges) – Rahiman

相關問題