i'm working on web project, , want try use knockoutjs. start, build app chrome (cause on official, knockout seems work ie8), when try web application in ie8, got many exceptions :
html :
<ul class="nav nav-tabs" id="tabs" data-bind="foreach: items"> <li data-bind="'id': 'id', css: { active: 'id' == $parent.selectedtab().id }, 'click': $parent.changetab"> <a data-toggle="tab" data-bind="text: name, attr: { 'href': 'href' }"></a> </li> </ul>
js :
var tabs = [ new tabviewmodel(1, "tab 1", true), new tabviewmodel(2, "tab 2", true), new tabviewmodel(3, "tab 3", false), ]; function tabviewmodel(id, name, enabled) { var self = this; self.id = ko.observable("test" + id); self.name = name; self.paneid = "tab" + id; self.href = ko.observable("#tab" + id); self.displayid = "header_tab" + id; self.enabled = ko.observable(enabled); ko.bindinghandlers.changestates = { init: function (element, valueaccessor) { var enable = valueaccessor(); if (enable) { $(element).removeclass("disabled"); } else { $(element).addclass("disabled"); } }, update: function (element, valueaccessor) { var enable = valueaccessor(); if (enable) { $(element).removeclass("disabled"); } else { $(element).addclass("disabled"); } } } } function surveyviewmodel(tabs) { var self = this; self.items = ko.observablearray(tabs); self.selectedtab = ko.observable(self.items()[0]); self.changetab = function (tab) { if (tab.enabled()) self.selectedtab(tab); return true; }; } ko.applybindings(new surveyviewmodel(tabs));
i have issues on :
- 2 line, 'changesstates' throw exception :
unable parse bindings. message: typeerror: object expected; bindings value
- 3 linen href property :
error: unable parse bindings. message: typeerror: 'href' undefined
thanks in advance
i pretty sure it's this:
var tabs = [ new tabviewmodel(1, "tab 1", true), new tabviewmodel(2, "tab 2", true), new tabviewmodel(3, "tab 3", false), ];
you have comma @ end. ie isn't smart, thinks meant have 4th item in array null.
Comments
Post a Comment