How to set a selected value in a dropdown list using Mustache.js?

后端 未结 4 1739
南旧
南旧 2020-12-30 01:06

Is it possible to do this with Mustache.js?

var data = {\"val\":\"3\"},
    template = \'{{#options}}' +
                   '' + 
               '{{/options}}';
var data={
    options: [
        {val: 1, txt: 'one'},
        {val: 2, txt: 'two'},
        {val: 3, txt: 'three'}
    ],
    selected: function() {
         if (this.val==selval) return "selected";
         return "";
    }
};


var html = Mustache.to_html(template, data);

提交回复
热议问题