bootstrap modal with knockout js binding不起作用

时间:2016-11-25 21:22:27

标签: javascript jquery knockout.js modal-dialog

我有一个带有敲除js的引导模态,但是每次我尝试加载模态时都会显示self.showmodalmoreborrowinfo is not a function,所以它让我感到困惑,为什么它不起作用。

这是js文件中的代码 通过初始化来打开模态

self.InitializeRegister = function(){
            if(self.openmodel() == 1){
                self.showmodalmoreborrowinfo();
            }
            self.showmodalmoreborrowinfo();
        }
        self.InitializeRegister();

此代码位于数据绑定的js末尾

// Custom binding handler for modal dialog.
    (function ($) {

        ko.bindingHandlers.bootstrapShowModal = {
            init: function (element, valueAccessor) {
                $(element).modal({ backdrop: 'static', keyboard: true, show: false });
            },
            update: function (element, valueAccessor) {
                var value = valueAccessor();
                if (ko.utils.unwrapObservable(value)) {
                    $(element).modal('show');
                    // this is to focus input field inside dialog
                    // $("input", element).focus();
                }
                else {
                    $(element).modal('hide');
                }
            }
        };
    })(jQuery);

这是html

<div data-bind="bootstrapShowModal: modalmoreborrowinfo" class="modal fade">
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="text-center">
                <H1>We need a bit more information for you to apply for borrowing</H1>
            </div>
            <br>
            <div class="text-center">
                <div class="form-group">
                    <input type="text" name="salary" data-bind="value: borrowersalary" class="form-control input-lg" placeholder="Salary">
                </div>
                <div class="form-group">
                    <input type="email" name="job" data-bind="value: borrowerjob" class="form-control input-lg" placeholder="Job">
                </div>
                <div class="form-group">
                    <input type="text" name="housing" data-bind="value: borrowerhousing" class="form-control input-lg" placeholder="Housing? eg Permanent">
                </div>
            </div> 
        </div>
    </div>
</div>

其他函数knockout js函数正在运行,只是这个不是。

0 个答案:

没有答案