1
我想動態呈現我的aurelia視圖,在repeater中使用撰寫和它工作正常,但我的雙向綁定不工作。使用compose元素呈現的視圖不會更新父視圖模型的屬性。Aurelia撰寫bind.two-way無法正常工作
我的父視圖的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如下所示。在這個網站我有上我的兩個綁定工作,但不能與撰寫
<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>