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