【问题标题】:Passing Custom Attributes into Aurelia Component将自定义属性传递给 Aurelia 组件
【发布时间】:2016-02-18 19:27:55
【问题描述】:

我在将属性传递到自定义组件时遇到了一些问题。我尝试通过以下方式声明我的组件:

<require from="../components/project-documents"></require>

<project-documents projectId="testing123"></project-documents>
<project-documents projectId.bind="project.Name"></project-documents>

import {customElement, bindable} from "aurelia-framework";
import {autoinject} from "aurelia-dependency-injection";

@customElement("project-documents")
export class ProjectDocuments {

    @bindable projectId:string;

    attached() {
        alert(this.projectId);
    }
}

当调用警报时, undefined 是我从中得到的值。另外,是否需要 customElement 装饰器?

【问题讨论】:

    标签: aurelia


    【解决方案1】:

    不要使用 camelCase 作为您的属性,而是尝试 d​​ash-case。

    试试这个:

    <project-documents project-id="testing123"></project-documents>
    <project-documents project-id.bind="project.Name"></project-documents>
    

    根据 aurelia 约定,破折号的属性将在您的 ViewModel 中转换为 camelCase 变量,因此您的 VM 已经很好了。

    【讨论】:

    • 做到了!该约定记录在哪里?
    • 对不起。我真的虽然在一些文档页面中描述了这个约定,但似乎不是。我一定读过一些我现在找不到的博客。
    • 我认为这是一个博客。我记得前阵子也看过。 Aurelia 仍然在您从任何可以找到的地方拼凑文档的时候。 :) 不过用起来很有趣。感谢您的帮助!
    • 模型应该是什么样子的?
    • @ShahidKarimi 模型与问题中发布的相同
    猜你喜欢
    • 2019-12-17
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    • 2021-02-08
    • 2021-11-11
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    相关资源
    最近更新 更多