javascript - Pass object to underscore.js template -
i'm trying pass object underscore.js (1.8.3) template , use in template script. simple example console:
> t = _.template("<% console.log(data) %>", {data: 42}) > t() uncaught referenceerror: data not defined
what correct way pass object template script use inside?
note: know substituting simple values, this:
t = _.template("<%= data %>") t({data:42}) <- "42"
but need pass , use objects in more complicated script.
update
this works:
> t = _.template("<% console.log(data) %>") > t({data: [1,2,3,4,5]})
i swear i'm not crazy (well not much)... looking @ this tutorial on backbone.js passes object template("...", object)
. perhaps way did in older version of underscore.js (version 1.4.2 in video)?
since version 1.7.0 underscore templates no longer accept initial data object. _.template
returns function now.
Comments
Post a Comment