【发布时间】:2016-08-05 08:31:20
【问题描述】:
我正在尝试动态渲染我的 aurelia 视图,在转发器中使用 compose,它工作正常,但我的双向绑定不起作用。使用 compose 元素渲染的视图不会更新父视图模型的属性。
我的父视图js文件代码是
export class Index {
public _items: interfaces.IBaseEntity[];
public data: string;
constructor() {
this._items = new Array<interfaces.IBaseEntity>();
this._items.push(new Address());
this._items.push(new HomeAddress());
}
activate() {
this._items.forEach((entity, index, arr) => {
entity.init();
});
//this.data = "data";
}
}
我的父 html 如下。在这个 html 中,我得到了自定义元素,我的两个绑定在该元素上有效,但不适用于 compose
<template>
<require from="form/my-element"></require>
<div repeat.for="item of _items">
<!--<my-element type.two-way="data" model.two-way="item.model"></my-element>-->
<compose view-model="${item.view}" model.two-way="item.model"></compose>
</div>
</template>
我的子视图模型
import * as interfaces from '../interfaces';
import {useView, bindable} from 'aurelia-framework';
export class Address implements interfaces.IBaseEntity {
public view: string = "form/address";
@bindable model: string;
constructor() {
console.log("address constructed - " + this.model);
}
init = (): void => {
this.model = "Address";
}
activate(bindingContext) {
this.model = bindingContext;
console.log("address ativated - " + this.model);
}
}
子视图html是
<template>
<h2>Address Template</h2>
<input type="text" value.two-way="model" class="form-control" />
</template>
【问题讨论】:
标签: aurelia