【发布时间】:2016-02-28 06:26:18
【问题描述】:
使用 Aurelia,假设我有一个自定义元素 <panel> 和一个视图/视图模型 InfoPanel。 <panel> 中有一个关闭按钮,它应该对 InfoPanel 执行一些操作,例如调用close()函数。
Panel.html
<template>
<h1>${headerText}</h1>
<button click.delegate="close()">x</button>
<content></content>
</template>
Panel.js
@bindable({name: "headerText"})
@bindable({name: "close"})
export class Panel {
}
InfoPanel.html
<template>
<require from="./Panel"></require>
<panel header-text="Info" close.bind="close">
<!-- content here -->
</panel>
</template>
InfoPanel.js
export class InfoPanel {
close() {
// At this point, "this" referse to the Panel, not the InfoPanel instance.
}
}
当我尝试这个时,我收到以下错误:
未捕获的错误:关闭不是函数
getFunction@aurelia-binding.js:2033
评估 @ aurelia-binding.js:1395
callSource@aurelia-binding.js:4842
(匿名函数)@aurelia-binding.js:4867
handleDelegatedEvent@aurelia-binding.js:2972
我的假设是 Aurelia 不清楚上下文,或者我遗漏了一些东西......
【问题讨论】:
-
谢谢。我不太了解如何使用它来解决我的问题。能否举个例子回答一下。
标签: javascript aurelia