小编fad*_*ril的帖子

Underscore.js模板渲染

我有这个示例代码使用下划线模板来呈现简单的unescapedHTML.

var template = $(this.el).html(_.template(this.template, {'data': '<script>'}));
$(this.parent).append(template);
Run Code Online (Sandbox Code Playgroud)

但是当它尝试渲染它时,它会导致错误:

未捕获的TypeError:对象[object Object]没有方法'replace'

任何人都可以请教我是什么原因以及如何解决它?由于在下划线文档中:

var template = _.template("<b>&lt;%- value %></b>");
template({value : '&lt;script&gt;'});
=> "<b>&lt;script&gt;</b>"
Run Code Online (Sandbox Code Playgroud)

提前致谢.

javascript backbone.js underscore.js underscore.js-templating

11
推荐指数
1
解决办法
3万
查看次数

如何在jQuery cookie中存储数组?

我正在打开一个基于此如何在jquery cookie中存储数组的新线程.我正在使用almog.ori的功能:

var cookieList = function(cookieName) {
//When the cookie is saved the items will be a comma seperated string
//So we will split the cookie by comma to get the original array
var cookie = $.cookie(cookieName);
//Load the items or a new array if null.
var items = cookie ? cookie.split(/,/) : new Array();

//Return a object that we can use to access the array.
//while hiding direct access to the declared items array
//this …
Run Code Online (Sandbox Code Playgroud)

jquery

4
推荐指数
1
解决办法
1万
查看次数