首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Aurelia compose Bind.双向不工作

Aurelia compose Bind.双向不工作
EN

Stack Overflow用户
提问于 2016-08-04 21:32:09
回答 1查看 956关注 0票数 1

我试图动态地渲染我的aurelia视图,在repeater中使用compose,它工作得很好,但我的双向绑定不起作用。使用compose元素呈现的视图不会更新父视图模型的属性。

我的父视图js文件的代码是

代码语言:javascript
复制
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。

代码语言:javascript
复制
<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>

我的子视图模型

代码语言:javascript
复制
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是

代码语言:javascript
复制
<template>
    <h2>Address Template</h2>
    <input type="text" value.two-way="model" class="form-control" />
</template>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-05 08:31:20

我现在知道问题所在了。我正在将简单的属性传递到我的compose中,这将不会起作用。它必须是一个对象

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38768808

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档