Ember.js 余烬工具提示传递变量
我正在构建一个余烬工具提示模块来创建悬停时的动态内容Ember.js 余烬工具提示传递变量,ember.js,Ember.js,我正在构建一个余烬工具提示模块来创建悬停时的动态内容 <div class="custom-tool-wrapper"> {{#custom-tool-tipster side="right" content=(or getContent question.id) contentAsHTML=true class="tool-tipster-field"}} Preview {{/custom-tool-tipster}
<div class="custom-tool-wrapper">
{{#custom-tool-tipster
side="right"
content=(or getContent question.id)
contentAsHTML=true
class="tool-tipster-field"}}
Preview
{{/custom-tool-tipster}}
</div>
我认为您实际上想要实现的是最好通过
问题
模型对象来实现(您的问题仍然很模糊)
然后说:
{{#custom-tool-tipster
side="right"
content=model.content
contentAsHTML=true
class="tool-tipster-field"}}
Preview
{{/custom-tool-tipster}}
如果您需要实际调用一个函数(很少会想到在涉及状态的情况下,computed属性不是更好的解决方案的实例),那么您可以使用自定义属性
(或a b)
是(a | | b)
,如果使用或
帮助程序的ember truth helpers
库,函数调用与您尝试的调用不一样。看起来你正在努力完成你所允许的事情
可以像
content=(调用此“getContent”question.id)
一样使用它来调用并返回传入上下文对象上的函数值(对于路由模板,如果this
,则为控制器)。让我澄清一下,我认为这种调用
方法是一个糟糕的想法,它真正摆脱了关注点的分离,我并不主张你这样做。模板不应该包含您的逻辑,而且当您拥有像computed properties这样的功能时,绝对不应该在控制器上调用任意函数 您希望(或getContent-question.id)
做什么?从您的问题中也不清楚您要问什么。将question.id传递到getContent中
content: computed('id', function(){
//this.tips is a part of the model object
//compute and return whatever the content is
return "content";
}
{{#custom-tool-tipster
side="right"
content=model.content
contentAsHTML=true
class="tool-tipster-field"}}
Preview
{{/custom-tool-tipster}}
import Ember from 'ember';
import { helper } from '@ember/component/helper';
export function invokeFunction([context, method, ...rest]) {
if (typeof context[method] !== 'function') {
throw new Error(`Method '${method}' is not defined or cannot be invoked.`);
}
return Ember.get(context,method).apply(context, rest);
}
export default helper(invokeFunction);