Mar*_*son 13 templates cross-browser internet-explorer-8 knockout.js
在所有"现代"浏览器中,以下工作但不在IE8中:
<!-- ko template: {if: $root.itemToEdit.SomeObject() === $data, name: 'EditItemTemplate', afterRender: $root.initializeEditPanel } -->
<!-- /ko -->
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
SCRIPT5022:无法解析绑定.消息:SyntaxError:预期的标识符,字符串或数字; 绑定值:template:{if:$ root.itemToEdit.SomeObject()=== $ data,name:'EditItemTemplate',afterRender:$ root.initializeEditPanel}
它似乎是if
在模板定义中包含语句.如果我将标记更改为以下内容,IE8很高兴:
<!-- ko if: $root.itemToEdit.SomeObject() === $data -->
<!-- ko template: {name: 'EditItemTemplate', afterRender: $root.initializeEditPanel } -->
<!-- /ko -->
<!-- /ko -->
Run Code Online (Sandbox Code Playgroud)
为什么if
在我的模板中包含一个语句在IE8中不起作用?
RP *_*yer 33
较旧的IE版本可以挑剔使用JavaScript保留字作为属性名称.如果你指定了if
类似的'if'
,那么你会没事的.喜欢:
<!-- ko template: {'if': $root.itemToEdit.SomeObject() === $data, name: 'EditItemTemplate', afterRender: $root.initializeEditPanel } -->
<!-- /ko -->
Run Code Online (Sandbox Code Playgroud)
或类似的东西 <label data-bind="attr : { 'for': id }"></label>