Passing data to underscore for rendering not working

*爱你&永不变心* 提交于 2019-12-02 02:51:05

this.template3 (and template1 and template2 for that matter) is a function which you call with the data as an argument to get the HTML back. In general:

var tmpl = _.template(template_source_text);
var html = tmpl(template_data);

You're just passing the template function to jQuery's html:

this.$('#noteParent').html(this.template3,data);

When you hand html a function, it calls the function but not with the arguments a template function expects:

.html( function )
Type: Function( Integer index, htmlString oldhtml ) => htmlString

A function returning the HTML content to set. Receives the index position of the element in the set and the old HTML value as arguments.

What you're doing is the same as saying:

this.$('#noteParent').html(this.template3(some_index, some_html));

You want to say:

this.$('#noteParent').html(this.template3(data));

so that the stuff in data is passed to the template function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!