使用弹出淘汰赛JS(Popup using knockout js)

2019-08-17 03:27发布

我正在迁移从DOM丛林我年长的jQuery插件之一,这个奇特MVVM框架淘汰赛。

哪种技术,我会用它来正确显示弹出式集装箱? 我ahve“通过电话”来填充它,因为我每次都得到一个JSON饲料。

我尝试过的方法使用具有约束力,但它仍试图填充部分在其第一次运行时。

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

Answer 1:

它可以在没有定制的结合以及完成。 实施例下面是

            <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 ...
   };


Answer 2:

创建一个自定义绑定,有它的开/关功能上可观察到触发。

我做了一个自定义为使用此approuch结合KO模板jQuery的对话框结合。

<div id="dialog" data-bind="dialog: { autoOpen: false, modal: true, title: dialogTitle }, template: { name: 'dialog-template', data: dialogItem, 'if': dialogItem }, openDialog: dialogItem"></div>

你可以找到我这里结合连同其他一些https://github.com/AndersMalmgren/Knockout.Bindings

现场演示http://jsfiddle.net/H8xWY/102/



Answer 3:

https://github.com/One-com/knockout-popupTemplate

这几乎做了你要求什么。 这是深深配置,并且在稳步发展(我们用它在我们的web应用程序自己)。

免责声明:我是One.com开发商。 我也是谁发起上述LIB的人。



文章来源: Popup using knockout js