当我使用 Knockout 模板绑定(bind)时,我在 IE8 中收到以下错误
Unhandled exception at line 58, column 28 in http://www.example.com/Scripts/knockout-2.2.0.js 0x800a01b6 - Microsoft JScript runtime error: Object doesn't support this property or method
我的代码:
HTML
<div data-bind="template : { name: 'person-template', foreach: people }"></div>
<script type="text/html" id="person-template">
<h3 data-bind="text: name"></h3>
<p>Credits: <span data-bind="text: credits"></span></p>
</script>
脚本
var UserTabViewModel = function () {
var self = this;
self.people = [{ name: 'Franklin', credits: 250 },
{ name: 'Mario', credits: 5800 }];
}
$(document).ready(function () {
var userTabViewModel = new UserTabViewModel();
ko.applyBindings(userTabViewModel);
});
它没有在任何其他浏览器中进行测试,因为我只安装了 IE8。
最佳答案
你的代码
var UserTabViewModel = function () {
var self = this;
self.people = [{ name: 'Franklin', credits: 250 },
{ name: 'Mario', credits: 5800 }];
}
$(document).ready(function () {
var userTabViewModel = new UserTabViewModel();
ko.applyBindings(userTabViewModel);
});
在 knockout 2.2.1 上运行良好
但 knockout 2.1.0 失败
尝试将 knockout 更新至 2.2.1。看来only corrects实际上这个错误! (错误出现在clean
上)
关于javascript - knockout JS : Template binding Issue in IE8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24503814/