2016-08-04 25 views
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> 

回答

0

我知道自定义元素问题现在。我将简单的财产传递给我的写作,这不会奏效。它必须是一个对象