【发布时间】:2016-05-15 05:26:31
【问题描述】:
我正在尝试使用 aurelia @children 装饰器在我的父容器视图模型中拥有所有子元素按钮,但这似乎不起作用。有没有人举个例子来说明@children 装饰器是如何工作的?
我想要做的是拥有一个包含一堆子元素(按钮)的父容器元素,并且在父容器中我试图通过引用所有父容器具有的按钮,因此每当用户单击按钮时,我都可以遍历按钮列表以查看之前已单击过哪些按钮。
目前,我在页面下方的代码无法加载 es6.promise.js:116 未处理的承诺拒绝类型错误:。
注释掉
@children('button') 按钮;
line 允许页面正常加载。感谢收看!
app.html
<template>
<require from="./custom-element"></require>
<my-custom-element>
<button class="btn btn-default" type="button">On</button>
<div>
This div falls back to <content> since nothing more specific chooses it. <br />
Notice how it is displayed last b/c of this.<br />
Remove <content /> element in custom element and this won't be used in the rendering of the custom element.
</div>
<div class="footer">Footer</div>
<button class="btn btn-default" type="button">Off</button>
</my-custom-element>
</template>
自定义元素.html
<template>
<content select="button"></content>
<content select="div.footer"></content>
<content></content>
</template>
custom-element.js
import {customElement, children} from 'aurelia-framework';
@customElement('my-custom-element')
export class MyCustomElement {
@children('button') buttons;
constructor() {
}
bind() {
console.log(this.buttons);
}
}
【问题讨论】:
标签: aurelia