【问题标题】:Aurelia: changing the name (attribute) of a bindableAurelia:更改可绑定的名称(属性)
【发布时间】:2017-06-04 02:12:52
【问题描述】:

我想知道是否可以在 Aurelia 中更改可绑定对象的名称(HTML 中的属性名称)。由于我们在当前项目中使用的编码标准,我们使用的属性名称非常难看,例如:m-data="someData"。我们为所有类成员加上 m 前缀。我知道我可以将它用于类,因此自定义元素名称是可自定义的,但我也可以为可绑定对象执行此操作吗?

例如:

// my-component.js

// I can use a decorator here to
// change the custom element name, which is great!
@customElement('my-component')
export class clsMyComponent {
  @bindable mData;
}

结果如下:

<!-- index.html -->

<my-component m-data.bind="someData"></my-component>

所以我想做但不起作用的是:

@customElement('my-component')
export class clsMyComponent {
  @bindable({name: 'data'}) mData;
}

我在这方面找不到任何东西,我知道您可以设置双向绑定、默认值等内容。但不是名称对吗?任何帮助将不胜感激!

【问题讨论】:

    标签: aurelia


    【解决方案1】:

    所以,经过一番研究,我找到了这个问题的正确答案。如Aurelia docs 中所述(搜索“可绑定签名”)。您可以像这样设置属性名称:

    @customElement('my-component')
    export class clsMyComponent {
      @bindable({attribute: 'data'}) mData;
    }
    

    生成的 HTML:

    <my-component data.bind="someData"></my-component>
    

    【讨论】:

    • 祝福你我的孩子
    猜你喜欢
    • 2016-06-08
    • 1970-01-01
    • 2012-01-18
    • 2011-09-01
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    相关资源
    最近更新 更多