Aurelia 的 "repeat.for" 可以与 "view-model.ref" 一起使用吗

Can Aurelia's "repeat.for" be used with "view-model.ref"

我在自定义元素上有一个 repeat.for(如果有 UI 个元素,请给我一个列表):

<box repeat.for="box of boxes" box.bind="box"></box>

我希望我的视图模型有一个自定义元素的视图模型列表(这样我就可以对列表中的每个项目调用验证方法。)

我试过这个:

<div repeat.for="box of boxes">
    <box box.bind="box" view-model.ref="boxViewModels[${$index}]"></box>
</div>

但是 boxViewModels 属性 没有将任何内容添加到数组中。 我什至试着看看它是否会在 repeat.for:

内部绑定
<div repeat.for="box of boxes">
    <box box.bind="box" view-model.ref="boxViewModelTesting"></box>
</div>

但是在我创建了几个实例之后,boxViewModelTestingundefined

让我想知道 view-model.ref 是否不能在 repeat.for 中工作。

有什么方法可以获取使用 'repeat.for' 创建的自定义属性的视图模型的引用?

这是测试套件中的一个场景。应该看起来像这样:

export class Foo {
  boxElements = [];
  boxViewModels = [];
  boxViews = [];
  boxControllers = [];
}
<template>
  <div repeat.for="box of boxes">
    <box ref="boxElements[$index]"
         view-model.ref="boxViewModels[$index]"
         view.ref="boxViews[$index]"     
         controller.ref="boxControllers[$index]">
    </box>
  </div>
</template>

Tests

您必须更新到 3/1/2016 版本的 Aurelia 才能使用此 http://blog.durandal.io/2016/03/01/aurelia-early-march-2016-update/