在 IE8 中使用条件淘汰模板 [英] Using conditional knockout templates with IE8

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

问题描述

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

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

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

我收到以下错误:

SCRIPT5022:无法解析绑定.消息:语法错误:预期标识符、字符串或数字;绑定值:模板:{如果:$root.itemToEdit.SomeObject() === $data, name: 'EditItemTemplate',afterRender: $root.initializeEditPanel }

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 }

似乎是在模板定义中包含了 if 语句.如果我将标记更改为以下内容,则 IE8 很高兴:

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 -->

为什么在我的模板中包含 if 语句在 IE8 中不起作用?

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

推荐答案

较旧的 IE 版本可能会挑剔使用 JavaScript 保留字作为属性名称.如果你像 'if' 一样指定 if ,那么你会没事的.喜欢:

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 -->

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

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

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