简体   繁体   English

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

[英]Can Aurelia's “repeat.for” be used with “view-model.ref”

I have a repeat.for on a custom element in my view (giving me a list if UI elements): 我在视图中的自定义元素上有一个repeat.for (如果UI元素给我一个列表):

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

I would like my view-model to have a list of the of the custom element's view-models (So I can call validate methods on each of the items in my list.) 我希望我的视图模型有一个自定义元素的视图模型列表(所以我可以在列表中的每个项目上调用validate方法。)

I tried this: 我试过这个:

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

But the boxViewModels property does not get anything added to the array. 但是boxViewModels属性不会将任何内容添加到数组中。 I even tried to see if it would bind at all inside of the repeat.for : 我甚至试图看看它是否会在repeat.for

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

But after I created a few instances, boxViewModelTesting is undefined . 但是在我创建了几个实例后, boxViewModelTestingundefined

Makes me wonder if view-model.ref just will not work inside a repeat.for . 让我想知道view-model.ref是否会在repeat.for

Is there any way to get the references of view-models of custom attributes created with a 'repeat.for'? 有没有办法获得用'repeat.for'创建的自定义属性的视图模型的引用?

This is a scenario that's part of the test suite. 这是测试套件的一部分。 Should look something like this: 应该看起来像这样:

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 测试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM