knockout.js - 延迟数据绑定模态? [英] knockout.js - deferred databinding for modal?

查看:143
本文介绍了knockout.js - 延迟数据绑定模态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用knockout.js来显示员工列表。我在页面上有一个隐藏的模式标记。当单个员工的详细信息按钮被点击时,我想将该员工的数据绑定到模态弹出窗口。我正在使用ko.applyBindings(employee,element),但问题是当页面加载时,它期待模式开始关闭某个东西。

I am using knockout.js to display a list of employees. I have a single hidden modal markup on the page. When the "details" button for a single employees is clicked, I want to data-bind that employee to the modal popup. I am using the ko.applyBindings(employee, element) but the problem is when the page loads, it is expecting the modal to start off as bound to something.

所以我想知道,是否有一个伎俩/策略来做延迟/延迟数据绑定?我查看了虚拟绑定,但文档没有足够的帮助。

So I'm wondering, is there a trick/strategy to do a late/deferred databinding? I looked into virtual bindings but the documentation was not helpful enough.

谢谢!

推荐答案

我将创建另一个可观察的包装员工。

I would create another observable that wraps the employee.

this.detailedEmployee = ko.observable({}),

var self = this;
this.showDetails = function(employee){
    self.detailedEmployee(employee);
    $("#dialog").dialog("show"); //or however your dialog works
}

将点击附加到 showDetails 。那么您可以在页面加载时调用 applyBindings

Attach the click to showDetails. Then you can just call applyBindings on page load.

这篇关于knockout.js - 延迟数据绑定模态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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