【发布时间】:2017-01-01 06:21:24
【问题描述】:
我有一个视图/视图模型对,它实现了弹出框自定义属性。我的具体目标包括在弹出框本身内单击按钮以及单击页面上的其他任何位置时关闭弹出框。
我可以让我的 doSomething() VM 函数在视图中的元素级别上工作,但不能在包含元素的属性内工作。我已经在代码 cmets 中进一步解释了这个问题。我会很感激一些指导。谢谢!
blog.html
<template>
<require from="../popover/popover"></require>
...
<!-- doSomething() works here! -->
<button type='button' click.trigger='doSomething()'>ClickMe</button>
<!-- doSomething() does not work here! -->
<!-- `click.trigger`/`click.delegate` does not trigger anything, while `onclick` shows
"Uncaught ReferenceError: doSomething is not defined" -->
<span class="glyphicon glyphicon-star" popover="title.bind: blogpost.title; placement.bind: 'top'"
data-content='<button type="button" click.trigger="doSomething()">ClickMe</button>' ></span>
...
</template>
blog.ts
...
doSomething() {
console.log('doing something');
}
popover.ts
...
bind() {
$(this.element).popover({
title: this.title,
placement: this.placement,
content: this.content,
trigger: 'click',
html: true
});
}
【问题讨论】:
-
你用的是什么popover插件?
-
@AshleyGrant Twitter Bootstrap,我大致遵循了这个:sitepoint.com/extending-html-aurelia-io-way
-
我在想 TemplatingEngine 可以用来提供弹出按钮 aurelia 绑定功能?
-
我要问问 Jeremy Danyow 能否在这方面为您提供帮助。他是我们的装订向导。
-
太棒了,谢谢@AshleyGrant!老实说,这可能很简单。我还尝试弄乱如何添加弹出框的内容,因为我认为这可能是错误的根源......上面我使用了
data-content属性,而<span class="glyphicon glyphicon-star" popover="title.bind: blogpost.title; placement.bind: 'top'; content.bind: 'my content';"></span>也可以使用。当我尝试在上面使用 html 而不是my content时,出现错误:Uncaught TypeError: this.sourceExpression.connect is not a function
标签: html mvvm data-binding typescript aurelia