Templates 在IE8中使用条件淘汰模板

Templates 在IE8中使用条件淘汰模板,templates,internet-explorer-8,cross-browser,knockout.js,Templates,Internet Explorer 8,Cross Browser,Knockout.js,在所有“现代”浏览器中,以下功能都有效,但在IE8中无效: <!-- ko template: {if: $root.itemToEdit.SomeObject() === $data, name: 'EditItemTemplate', afterRender: $root.initializeEditPanel } --> <!-- /ko --> 为什么在我的模板中包含if语句在IE8中不起作用?较旧的IE版本可能会对使用JavaScript保留字作为属性名很挑剔

在所有“现代”浏览器中,以下功能都有效,但在IE8中无效:

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

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

较旧的IE版本可能会对使用JavaScript保留字作为属性名很挑剔。如果您像指定
'If'
那样指定
If
,那么您就可以了。比如:

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


或者类似的

是的。这就解决了问题。谢谢,Ryan。我可能会在这里以问答的形式发布这篇文章,但现在,只是因为我花了5个小时试图解决这个问题。。。如果您对IE8和KO模板有问题,请确保您的实际模板不在任何KO if块中。我在页面的各个部分都有我的模板,只是在IE8中有问题。将它们全部移到身体顶部,现在效果很好。@eselk您写评论至少为我节省了5个小时。非常感谢。天哪!没有理由认为这应该修复IE8中出现的奇怪的内存泄漏…我在KO修复方面读到的最有用的一点废话…而且对于模板中的“如果”来说…天啊。也不喜欢关键字类,因为“如果”必须在引号中使用它。
<!-- ko template: {'if': $root.itemToEdit.SomeObject() === $data, name: 'EditItemTemplate', afterRender: $root.initializeEditPanel } -->
<!-- /ko -->