knockout.js:在< select>上使用无容器foreach在Internet Explorer 8中失败 [英] knockout.js: using a containerless foreach on a <select> fails in Internet Explorer 8

查看:178
本文介绍了knockout.js:在< select>上使用无容器foreach在Internet Explorer 8中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RP Niemeyer 的文章 Knockout.js Performance Gotcha#3 - All Bindings Fire Together
一种建筑方法提供下拉列表:

In RP Niemeyer's article Knockout.js Performance Gotcha #3 - All Bindings Fire Together, an approach to building a dropdown list is provided:

<select data-bind="value: selectedOption">
    <!-- ko foreach: options -->
    <option data-bind="attr: { value: id }, text: name"></option>
    <!-- /ko -->
</select>

此代码也在文章的jsfiddle中。

This code is also in a jsfiddle from the article.

http://jsfiddle.net/rniemeyer/ QjVNX /

但是,当我在项目中使用这种方法构建选择时,
它正在工作很好,直到我在Internet Explorer 8中测试过.IE8失败并且
无法解析绑定。

However, when I employed this method of building a select in a project, it was working just fine, until I tested in Internet Explorer 8. IE8 failed and was "unable to parse bindings".

的确,从IE8中的文章中运行小提琴也会导致错误。
有没有办法在IE8中构建 select (我假设IE8或更少)
使用knockout的foreach?

Indeed, running the fiddle from the article in IE8 also results in an error. Is there a way to build the select in IE8 (I assume IE8 or less) using knockout's foreach?

推荐答案

是的,这绝对是一个问题。我将不得不更新帖子。 IE将从select中删除注释。

Yes, that is definitely an issue. I will have to update the post. IE will strip comments from inside the select.

这是我们在github上看到的类似问题: https://github.com/SteveSanderson/knockout/issues/578

Here is an issue that we saw on github that is similar: https://github.com/SteveSanderson/knockout/issues/578

One解决方案是使用Michael Best的重复绑定: https: //github.com/mbest/knockout-repeat

One solution is to use Michael Best's repeat binding: https://github.com/mbest/knockout-repeat.

它允许你做的一件事就是多次重复单个元素不同的背景。因此,在这种情况下,它的行为类似于无容器语法,只是没有注释。

One of the things that it allows you to do is repeat a single element multiple times with a different context. So, in that case it would act similar to the containerless syntax, just without the comments.

重复示例: http://jsfiddle.net/rniemeyer/QjVNX/

您也可以选择使用文章中的另一种技术( isolatedOptions ),除非你需要更多地控制你的选项元素。

You can also choose to use the other technique from the article (isolatedOptions), unless you need more control over your option elements.

这篇关于knockout.js:在&lt; select&gt;上使用无容器foreach在Internet Explorer 8中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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