var self = this;
self.filters = {
genres: [],
...
};
self.getLibrary = function() {
$.getJSON("library.json", function(data) {
for (var i=0, l=data.filters.genres.length; i<l; i++) {
self.filters.genres.push({genre: data.filters.genres[i]});
}
...
$.each(self.filters, function(k1,v1) {
var tmpl = "{{#" + k1+ "}}{{" + k1.slice(0, -1) + "}}{{/" + k1 + "}}";
var html = Mustache.render(tmpl, self.filters[k1]);
$("#" + k1).html(html);
});
...
}
});
};
记录tmpl变量会产生以下结果:
{{#genres}}{{genre}}{{/genres}}
记录self.filters[k1]
会产生如下数组:
[
{genre: "Ambient"},
{genre: "Bass"},
...
]
记录html变量会产生一个空白字符串。
我该如何解决这个问题?
答案 0 :(得分:0)
终于解决了问题:
var html = Mustache.render(tmpl, self.filters[k1]);
=&GT;
var html = Mustache.render(tmpl, self.filters);