使用条件敲除模板与IE8 [英] Using conditional knockout templates with IE8

查看:79
本文介绍了使用条件敲除模板与IE8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有现代浏览器中,以下工作但不在IE8中:

  ! -  ko template:{if:$ root.itemToEdit.SomeObject()=== $ data,name:'EditItemTemplate',afterRender:$ root.initializeEditPanel}  - > 
<! - / ko - >

我得到以下错误:


SCRIPT5022:无法解析绑定。消息:SyntaxError:Expected
标识符,字符串或数字; Bindings值: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 - >
我的模板中的语句不能在IE8中使用?

解决方案

旧版IE可以选择使用JavaScript保留字属性名称。如果你指定 if 像'if',那么你会没事的。 like:

 <! -  ko template:{'if':$ root.itemToEdit.SomeObject()=== $ data,name:'EditItemTemplate',afterRender:$ root.initializeEditPanel}  - > 
<! - / ko - >

或者像< label data-bind =attr:{' for':id}>< / label>


In all 'modern' browsers the following works but not in IE8:

<!-- ko template: {if: $root.itemToEdit.SomeObject() === $data, name: 'EditItemTemplate', afterRender: $root.initializeEditPanel } -->
<!-- /ko -->

I get the following error:

SCRIPT5022: Unable to parse bindings. Message: SyntaxError: Expected identifier, string or number; Bindings value: template: {if: $root.itemToEdit.SomeObject() === $data, name: 'EditItemTemplate', afterRender: $root.initializeEditPanel }

It seems to be the inclusion of the if statement inside the template definition. If I change the markup to the following, IE8 is happy:

<!-- ko if: $root.itemToEdit.SomeObject() === $data -->
   <!-- ko template: {name: 'EditItemTemplate', afterRender: $root.initializeEditPanel } -->
   <!-- /ko -->
<!-- /ko -->

Why does including an if statement in my template not work in IE8?

解决方案

Older IE versions can be picky about using JavaScript reserved words for property names. If you specify the if like 'if', then you will be fine. Like:

<!-- ko template: {'if': $root.itemToEdit.SomeObject() === $data, name: 'EditItemTemplate', afterRender: $root.initializeEditPanel } -->
<!-- /ko -->

Or something like <label data-bind="attr : { 'for': id }"></label>

这篇关于使用条件敲除模板与IE8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆