淘汰赛js:"with"绑定破坏了jQuery UI [英] knockout js: The "with" binding breaks the jquery ui

查看:120
本文介绍了淘汰赛js:"with"绑定破坏了jQuery UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://jsfiddle.net/AYPze/9/

在此示例中,我有两个具有相同目标的相似div.从datetimepicker绑定选定的日期,并将其保存到由剔除js绑定的对象.

In this example I have two similar divs with the same goal. Bind the selected date from the datetimepicker and save it to the object binded by knockout js.

第一个div的问题是datetimepicker不会显示,因为我使用了敲除的"with"绑定.

The problem with the first div is that the datetimepicker won't show up because i use the knockout "with" binding.

第二个div使用常规的敲除js绑定语法,该语法在datetimepicker上正常工作.

The second div uses the normal knockout js binding syntax, which works fine with the datetimepicker.

我在jquery-ui手风琴上也遇到了这种情况

I experienced this behavior also with the jquery-ui Accordion

我的问题: 这是敲除或jquery-ui中的错误吗? 有没有解决的办法,所以我可以使用"with"绑定?

My Questions: Is this a bug in knockout or jquery-ui? Is there a work around, so I can use the "with" binding?

推荐答案

您的问题与 with 绑定有关,但与您的想法无关.

Your problem is related to the with binding, but not in the way you think.

您遇到的问题是,在这种情况下, with 绑定将从DOM元素中删除jQuery datepicker,这就是为什么您看不到第一个文本框的日期选择器的原因.

The problem you have is that the with binding in this case will remove the jQuery datepicker from the DOM element and that is why you don't see the datepicker for the first textbox.

这里的主要问题是,在使用Knockout和DOM时,您正在打破一个非常重要的规则.您不应该像现在这样直接使用jQuery直接访问DOM.您必须使用bindingHandler来弥合数据模型和DOM模型之间的鸿沟.

The main problem here is that you are breaking a very important rule when working with Knockout and the DOM. You shouldn't access the DOM directly with jQuery like you are doing now. You have to use a bindingHandler to bridge the gap between your data model and the DOM model.

起初,绑定处理程序似乎很复杂,但是一旦您了解它们,它们就会非常方便.

The Binding Handlers seem complex at first, but they are pretty handy once you get to know them.

这是您的提琴的更新版本,带有有效的日期选择器: http://jsfiddle.net/AYPze/10/

Here is an updated version of your fiddle with a working datepicker: http://jsfiddle.net/AYPze/10/

这篇关于淘汰赛js:"with"绑定破坏了jQuery UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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