gpt4 book ai didi

javascript - 弹窗使用knockout js

转载 作者:数据小太阳 更新时间:2023-10-29 05:46:54 25 4
gpt4 key购买 nike

我正在将我的一个旧 jquery 插件从 DOM jungle 迁移到这个奇特的 mvvm 框架 knockout 。

我应该使用哪种技术来正确显示弹出容器?我必须“通过电话”填充它,因为我每次都会收到一个 json 提要。

我尝试了一种使用 with 绑定(bind)的方法,但它仍会尝试在其第一次运行时填充部分内容。

<!-- ko with: daySubmitFormViewModel -->
<div class="ec-consulation-lightbox">
<form id="cForm" class="form-container">
// Some bindings here.
</form>
</div>
<!-- /ko with: -->

最佳答案

它也可以在没有自定义绑定(bind)的情况下完成。示例如下

            <div class="modalWindowBackground" data-bind="visible: popupDialog" >
<div class="modalWindow" data-bind="with:popupDialog">
<div class="content">
<h2 data-bind="text: title"></h2>
<p>
<span data-bind="text: message"></span>
</p>
<div class="buttonSpace">
<input type="button" class="closeButton" data-bind="value: closeButtonText, click: $root.hidePopupDialog" />
</div>
</div>
</div>
</div>

查看模型代码:

    self.showAlert = function (title, message, closeButtonText) {
self.popupDialog({ title: title, message: message, closeButtonText: closeButtonText });
};
self.hidePopupDialog = function () {
self.popupDialog(null);
};

//Code which opens a popup
self.remove = function () {
.... some code ...
if (someCondition) {
self.showAlert('SomeTitle', 'Message', 'OK');
return;
}
.... some code ...
};

关于javascript - 弹窗使用knockout js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15053563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com