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 变量会产生一个空白字符串。
我该如何解决?