KnockoutJS:Internet Explorer中的多选问题
KnockoutJS: multiselect issue in Internet Explorer
我有一个非常简单的例子,使用KnockoutJS 3的多选select
元素。如果将selectedOptions
绑定与具有IE(任何版本)的多选元素一起使用,则在选择新选项时,select元素始终会反弹到最底部的选定元素。我看过很多文章,这些文章似乎与此有关,而且非常过时,但没有明确的解决方案。感谢您的帮助。
这里的简单示例:
http://jsfiddle.net/unp9j9dc/1
通过单击项目1,保持控制,单击项目20,然后返回项目2进行复制。UI将反弹到项目20。
此外,我应该提到的是,虽然JSFiddle使用的是敲除3.0.0,但我在本地使用的是3.2.0,结果相同。我很快就会试用3.3.0。
UPDATE:与Knockout 3.3.0的结果相同。
我明白了。我非常广泛地使用订阅和双向绑定,所有这些似乎仍然可以正常工作。
基本上,KO基础设施只是通过UI或模型更新上的更新模型绑定来完成并同步UI。因此,它在UI更新上设置每个选项的selected
属性,当它"重新选择"最后一个选项时,IE决定将其滚动到视图中。
我采用了Knockout 3.2.0的调试版本,并编辑了第305-310行,如果选项的选定属性已经等于正在设置的属性,则不尝试更新该属性。我计划在有时间的时候提交一个拉取请求,但如果有其他人遇到这种情况,就在这里。
更新:再次感谢@JamesThorpe,这是我编辑的来源。
setOptionNodeSelectionState: function (optionNode, isSelected) {
// IE6 sometimes throws "unknown error" if you try to write to .selected directly, whereas Firefox struggles with setAttribute. Pick one based on browser.
if (ieVersion < 7)
optionNode.setAttribute("selected", isSelected);
else if (optionNode.selected != isSelected)
optionNode.selected = isSelected;
},
相关文章:
- Backbone.js路由器和Internet Explorer重定向问题
- 如果调试器关闭,Internet Explorer将出现运行代码问题
- 使用大括号的 Internet Explorer 上的 AngularJS 数据绑定问题
- Internet Explorer 中的 JavaScript 方向更改问题
- 在internet explorer上使用jquery时出现问题
- KnockoutJS:Internet Explorer中的多选问题
- 在Internet Explorer 11中使用SoundCloud进行身份验证时出现问题
- Highcharts 4.0.4 Internet Explorer上的导出问题
- 这个Javascript出了什么问题"Internet Explorer无法打开Internet站点-操作中止
- 在Internet Explorer 8中的Iframe中创建TinyMCE时出现问题
- 禁用 Internet Explorer 8 jQuery 中的缓存问题
- Internet Explorer Ajax 调用,缓存响应问题
- Internet Explorer 9 和 JavaScript 变量范围问题
- Internet Explorer 中的 Json 响应问题
- 当单击 shift + 鼠标左键单击时,Internet Explorer 浏览器问题 ,文本会自动突出显示
- BHO Internet Explorer插件-脚本注入问题
- 使用Internet Explorer更新Kendo DropDownList时出现问题
- 从PowerShell打开Internet Explorer时出现问题
- HTML5拖放;Internet Explorer中的删除问题(无法访问dataTransfer属性)
- 长轮询-Internet Explorer 8的问题