使用Aurelia,说我有一个自定义元素<panel>
和视图/查看模型InfoPanel
。 <panel>
有一个关闭按钮,它应该对InfoPanel
执行一些操作,例如,调用close()
函数。如何访问Aurelia中的嵌套模型?
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.
}
}
当我尝试,我得到了以下错误:
Uncaught Error: close is not a function
getFunction @ aurelia-binding.js:2033
evaluate @ aurelia-binding.js:1395
callSource @ aurelia-binding.js:4842
(anonymous function) @ aurelia-binding.js:4867
handleDelegatedEvent @ aurelia-binding.js:2972
我的假设是,上下文不清楚Aurelia路上,或者我失去了一些东西...
尝试 “裁判”,在这里看到:http://aurelia.io/docs.html#/aurelia/framework/1.0.0-beta.1.1.3/doc/article/cheat -sheet/5 –
谢谢。我不太关注如何使用它来解决我的问题。你能举一个例子来回答吗? –