0
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 变量会产生一个空白字符串。

我该如何解决?

4

1 回答 1

0

终于解决了问题:

var html = Mustache.render(tmpl, self.filters[k1]);

=>

var html = Mustache.render(tmpl, self.filters);

于 2013-10-11T17:08:24.677 回答