knockout.js - 模式的延迟数据绑定?

knockout.js - deferred databinding for modal?(knockout.js - 模式的延迟数据绑定?)
本文介绍了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.

谢谢!

推荐答案

我会创建另一个包裹员工的 observable.

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 - 模式的延迟数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)