Aurelia - 在数据绑定中使用变量作为 属性 的名称

Aurelia - Using variable as name of property in data binding

使用 Aurelia,是否可以使用变量名动态引用模型对象的 属性 名称?

Javascript:

dow = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'];
test = {
    monday:     false,
    tuesday:    false,
    wednesday:  false,
    thursday:   false,
    friday:     false,
};

HTML:

<label repeat.for="day of dow"><input type="checkbox" class="form-control" checked.bind="test[day]" />${day}</label>

这导致:"TypeError: obj is undefined"

根据 Aurelia 文档:

Each item that is being repeated by the repeat attribute has several special contextual values available for binding:

$parent - At present, the main view model's properties and methods are not visible from within the repeated item. We hope to remedy this in an update soon. For the mean time, you can access that view-model with $parent.

$index - The index of the item in the array.

$first - True if the item is the first item in the array.

$last - True if the item is the last item in the array.

$even - True if the item has an even numbered index.

$odd - True if the item has an odd numbered index.

在将 HTML 更新为引用 parent.new_deal[天]:

后它起作用了
<label repeat.for="day of dow"><input type="checkbox" class="checkbox-inline" checked.bind="$parent.new_deal[day]" />${day}</label>