调用一个函数下划线模板使用骨干网内部 [英] Call a function inside an underscore template using backbone
本文介绍了调用一个函数下划线模板使用骨干网内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是一个事情,我尝试这样做,真的会简化我现在的生活。
Just a thing I try to do that would really simplify my life right now.
我怎么能做到这一点:
这是我的应用程序文件视图
This is my view in app file
window.ArtView = Backbone.View.extend({
template:_.template($('#art').html()),
render:function (eventName) {
var output="blablbla";
$(this.el).html(this.template({"output":output}));
return this;
}
});
...
// function that I would like to call
function callFunction(){
console.log('it works!');
}
在模板的index.html
Template in index.html
<script type="text/tempate" id="art">
<div data-role="header" class="header" data-position="fixed">
<a href="#" data-icon="back" class="back ui-btn-left">Back</a>
</div>
<div data-role="content" class="content">
callFunction();
<% console.log(output) %>
</div>
</script>
我怎么能叫callFunction()我的模板或相似的东西里面?
How can I call callFunction() inside my template or something alike ?
任何想法?
谢谢!
推荐答案
我相信你可以,只要模板的对象所具有的功能在模板中调用函数。
I believe you can call functions within the template as long as the object for the template has the function.
render:function (eventName) {
var output="blablbla";
var data = _.extend({"output":output}, callFunction);
$(this.el).html(this.template(data));
return this;
}
然后在你的模板:
then in your template:
<%= callFunction() %>
这篇关于调用一个函数下划线模板使用骨干网内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文