【发布时间】:2014-08-18 21:12:27
【问题描述】:
我有一个这样的数组,我正在尝试用一个选择来绑定它。
var arr = [{
"Id": 1,
"Rate": 5,
"Price": 200,
"Name": "History",
"template": "<option id='1'>History</option>"
}, {
"Id": 2,
"Rate": 5,
"Price": 150,
"Name": "Geographic",
"template": "<option id='2'>Geographic</option>"
}, {
"Id": 3,
"Rate": 1,
"Price": 75,
"Name": "Maths",
"template": "<option id='3'>Maths</option>"
}, {
"Id": 4,
"Rate": 2,
"Price": 50,
"Name": "Statistics",
"template": "<option id='4'>Statistics</option>"
}, {
"Id": 5,
"Rate": 3,
"Price": 120,
"Name": "Drawing",
"template": "<option id='5'>Drawing</option>"
}]
如您所见,有一个包含选项字符串的模板。这是我用一些功能创建的。现在我想绑定这个数组来选择。
self.Result = ko.observableArray(arr)
查看
<select data-bind="foreach:Result">
<!-- ko html:$data.template -->
<!-- /ko -->
</select>
现在它产生了一个错误。 html 绑定不能与虚拟元素一起使用。
如果我试试这个
ko.virtualElements.allowedBindings.html = true;
它不能解决问题,因为我认为它仅适用于自定义绑定。
有什么解决办法吗?如果我需要这样做,我应该怎么做
【问题讨论】: