Force show.bind execution

吃可爱长大的小学妹 提交于 2019-12-12 17:32:27

问题


I have a table with data, and i want view to check show.bind statement when the event is fired from another view. The problem is that the event is not changing any data in the current view.

foo.html:

 <tr repeat.for="entity of viewData.entities">
  ...
    <p if.bind="$parent.canBeRemoved(entity.id)">
     canBeRemoved
    </p>
 ...
 </tr>

I'm receiving the event with EventAggregator and i want it to force refresh on the array. Is it possible?


回答1:


Use the signal binding behavior

The best way to handle this is to send a signal through the signal binding behavior.

template.html

<tr repeat.for="entity of viewData.entities">
  ...
  <p if.bind="$parent.canBeRemoved(entity.id) & signal:'update-view'">
    canBeRemoved
  </p>
  ...
</tr>

viewModel.ts

import {BindingSignaler} from 'aurelia-templating-resources';

// grab a reference to the signaler
constructor(signaler: BindingSignaler) {
    this.signaler = signaler;
}

// and fire the signal event bound in your view
// whenever the event is handled
respondToEvent(event) {
    // do eventy things
    this.signaler.signal('update-view');
}



回答2:


You could use a getter function. For instance:

JS

export class Entity {

    //@computedFrom('property1', 'property2')
    get canBeRemoved() {
       //your magic here
       //return true or false;
    }
}

HTML

 <tr repeat.for="entity of viewData.entities">
  ...
    <p if.bind="entity.canBeRemoved">
     canBeRemoved
    </p>
 ...
 </tr>


来源:https://stackoverflow.com/questions/38638482/force-show-bind-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!