5

更新:

其他人报告说这个样本对他们很有效。听起来我做错了什么,但我没有代码了,所以我无法检查问题是什么。

原始问题:

我有以下带有以下视图模型和视图的自定义元素:

import {bindable} from 'aurelia-framework';
export class Test1 {
  @bindable name = null;
}

<template>
  <div>Name: ${name}</div>
</template>

然后我有一个使用上述自定义元素的视图和视图模型(这是骨架项目中的欢迎页面):

export class Welcome {
  constructor() {
    this.name = 'Test';
  }
}

<template>
  <require from="./components/test1"></require>
  <test1 name.bind="name"></test1>
</template>

我的期望是看到“名称:测试”,但我只得到“名称:”。如果我使用字符串并删除“.bind”,那么它可以工作:

<test1 name="Test"></test1>

但我希望它在我更新“App”视图模型中的“name”字段时自动更新。

我不确定我做错了什么。我在控制台中看不到任何错误。

这个例子基于 Aurelia 的骨架示例项目。aurelia-framework 的版本是 0.11.0。

4

1 回答 1

1

“欢迎”类中的道具“名称”应该是可绑定的。

import {bindable} from 'aurelia-framework';

export class Welcome {
  @bindable name = ''

  constructor() {
    this.name = 'Test';
  }
}
于 2015-07-28T11:33:25.263 回答