observableArray绑定表中没有一个jQuery UI对话框内部时更新 [英] observableArray bound table does not update when inside a jQuery UI dialog

查看:151
本文介绍了observableArray绑定表中没有一个jQuery UI对话框内部时更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个按钮,点击后会打开一个模式对话框,允许用户搜索产品,并添加选择的搜索结果的顺序创建页面。

I'm trying to create a page with a button which, when clicked, opens a modal dialog box that allows a user to search for products and add selected search results to an order.

我已经创建了我认为会的工作(的jsfiddle样品),但在搜索结果表,这势必给 observableArray ,不更新。

I've created what I thought would work (jsfiddle sample), however the search results table, which is bound to an observableArray, does not update.

如果我删除从&LT的数据绑定属性; DIV ID =myDialog/> 然后在搜索结果表正确更新。

If I remove the data-bind attribute from the <div id="myDialog"/> then the search results table updates correctly.

另外,我只能得到的jsfiddle样品通过将JavaScript中的主体(框架选项的没有包装(车身)的)重复同样的行为,即使脚本中加载的< A HREF =htt​​p://api.jquery.com/ready/相对=nofollow>就绪()回调在实际执行中。

Also, I could only get the jsfiddle sample to repeat the same behaviour by placing the JavaScript in the body (framework option no wrap (body)), even though the script is loaded during the ready() callback in the actual implementation.

我在哪里去了?

(我这里公布我所有的code 。)

(I've posted all my code here.)

更新:

这似乎是淘汰赛的foreach 绑定无法看到更新的 observableArray 。我已经创建了自己的绑定(更新的jsfiddle样品)模板几乎我想要做什么,但不是很满意。

It seems like the Knockout foreach binding fails to see the updates to the observableArray. I've created my own binding (updated jsfiddle sample) template which almost does what I want, but is not very satisfactory.

我怎样才能获得的foreach 绑定识别集合时发生了变化?

How can I get the foreach binding to recognise when the collection has changed?

推荐答案

下面是你破碎的样品与细微的修改来调用 .dialog()中的setTimeout: http://jsfiddle.net/rniemeyer/YuV55/5/ 。在jQuery UI的对话框功能移动元素到页面的底部,所以它可以搞砸绑定为 ko.applyBindings 的初始通击中它的第二个时间。

Here is your broken sample with a minor modification to call the .dialog() in a setTimeout: http://jsfiddle.net/rniemeyer/YuV55/5/. The jQuery UI dialog functionality moves the element to the bottom of the page, so it can mess up the bindings as the initial pass of ko.applyBindings hits it for a second time.

下面是调用 ko.applyBindings 具体到一个容器元素(不setTimeout的)另一个样品:的 http://jsfiddle.net/rniemeyer/YuV55/6/ 。这意味着 ko.applyBindings 不会碰到移动对话框中的第二次,因为这将是容器元素之外。

Here is another sample that calls ko.applyBindings specific to a container element (without the setTimeout): http://jsfiddle.net/rniemeyer/YuV55/6/. This means that ko.applyBindings won't hit the moved dialog the second time, as it will be outside of the container element.

这篇关于observableArray绑定表中没有一个jQuery UI对话框内部时更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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