I have a component which has a grid-child-component. I pass the data to the grid from the parent:
<grid data.bind=data> </grid>
After the data is updated in the parent, I also need to be refresh / rebinded in child. Currently, it is not.
Data is an object: data: {items: myType[], otherData: number}
How could I achieve that?
You can use change handler to achieve what you want. Suppose this is your current <grid/> class:
export class Grid {
@bindable() data;
bind() {
// do stuff A
// do stuff B
}
}
What you can do is to extract the body of bind() out into a method that handle data change, then it will be automatically called whenever data from parent of the <grid/> changes:
export class Grid {
@bindable() data;
bind() {
this.dataChanged(this.data);
}
dataChanged(newData) {
// do stuff A
// do stuff B
}
}
Now I have different problem. In my grid I have a repeat.for, which contains a call to a method to draw an icon depending on the value of an value This value is updated in my grid, however, the method is not being called and the old icon keeps there.
It sounds like you are hitting some issues with binding update. There are many solutions but it will take some example code to help understand what you want to achieve.
In getIcon, i really need item.status, so, “item” does not changed but the inner attribute status. For that reason, class.bind didn’t call to getIcon(item) again.