repeat.for 中的 Aurelia 绑定不起作用

Aurelia binding in repeat.for not working

我试图在 repeat.for 中的 aurelia 组件上设置一个可绑定值,但它似乎没有任何影响。

<event-summary repeat.for="event of events" event.bind="event" is-favorite="true"></event-summary>

并在视图模型中

事件-summary.js

@bindable('isFavorite')
@bindable('event')
export class EventSummary {
    bind(bindingContext) {
        if(bindingContext.isFavorite == null) {
            this.isFavorite = false;
        }
    }
}

事件设置正确,但 isFavorite 始终未定义,无论我尝试什么(is-favorite.bind="[some vm value]")也 returns 未定义。谁能告诉我为什么?

谢谢

我从未使用过 bind() 函数,但通常你的作用域上有 isFavorite,比如 this.isFavorite。你也可以在构造函数中进行空检查

这对我有用:

import {bindable} from 'aurelia-framework';

export class Testelement {

    @bindable item
    @bindable isFavorite
    constructor() {
        console.log(this.isFavorite);
        console.log(this.item);
    }

    bind(bindingContext, overrideContext) {
        console.log("bc ", bindingContext); //no item or isFavorite defined here
        console.log("oc ", overrideContext);//no item or isFavorite defined here
    }
}


<testelement item.bind="element" repeat.for="element of data" is-favorite="true"></testelement>

is-favorite.bind="true" 应该可以。 is-favorite="true" 也应该工作,尽管在这种情况下 isFavorite 可绑定 属性 将被分配字符串 'true'。这是两者的可运行示例: https://gist.run/?id=7044b0c37b53bb66e833d461f41dae2f