【问题标题】:@children decorator not working in aurelia for me@children 装饰师不在 aurelia 为我工作
【发布时间】: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 &lt;content&gt; since nothing more specific chooses it. <br />
        Notice how it is displayed last b/c of this.<br />
        Remove &lt;content /&gt; 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


    【解决方案1】:

    这是我发现的同步和子示例之间的内容。

    @customElement('my-custom-element')
    @children({ name: "buttons", selector: "button" })
    export class MyCustomElement {
      bind() {
        console.log(this.buttons);
      }
    }
    

    尝试遍历子元素查找元素时也会出现问题。

    Not Traversing Child Elements

    【讨论】:

      猜你喜欢
      • 2016-02-08
      • 2011-02-11
      • 2012-01-15
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 2010-10-16
      • 2012-04-10
      • 2012-01-15
      相关资源
      最近更新 更多