我的要求是我需要向用户显示一组选项。我使用了 mustache 模板来使用 CanJS javascript 框架呈现选项。
这里的问题是当我试图呈现如下选项时:Potato Rs。12
mustache 模板正在转义我的 HTML,并使用 HTML 标记显示值。
我在我的模板中也使用了 {{{ }}},但它没有帮助。
请检查小提琴是否相同。
http://jsfiddle.net/arvi87/22CU8/1/
我的小胡子模板:
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{{display}}}</option>
{{/options}}
我将数据绑定到模板的示例控件:
var frag = can.view('{{' +this.options.view+ '}}',{
/*
I am passing observe here which is escaping the HTML tags like:
Cabbage <span>Price: Rs.12</span>
*/
options: arrayObserver
/*
This is rendering properly. Not sure about what is the difference ?
Cabbage Price: Rs.12
*/
//options: array
});
我的选项数组:
var array = [{
selected: true,
display: "None"
},{
selected: false,
display: "Tomato"
},{
selected: false,
display: "Potato <span>Rs.10</span>"
},{
selected: false,
display: 'Cabbage <span>Price: Rs.12</span>'
}];
arrayObserver = new can.Observe.List(array);
任何帮助都会很棒。
谢谢。