【发布时间】:2014-04-29 01:47:13
【问题描述】:
尽管我使用 Underscore 的 _.template() 定义了 @template,但我在 @template 上得到了 Uncaught TypeError: undefined is not a function
IntroProject.Views.Posts ||= {}
class IntroProject.Views.Posts.IndexView extends Backbone.View
el: '#posts'
template: _.template( $('#home-post-template').html() ) if $('#home-post-template').length
initialize: ->
@collection.bind "reset", ->
@render()
, @
render: ->
@collection.each (post) ->
console.log @template( post.attributes )
@
当我执行console.log @template 时,如果在渲染函数中调用,我会得到undefined。当我从initialize 中调用console.log @template 时,我得到了
function (data) {
return render.call(this, data, _);
}
【问题讨论】:
标签: javascript jquery templates backbone.js underscore.js