繁体   English   中英

KnockoutJS-引导程序3模态绑定不起作用

[英]KnockoutJS - bootstrap 3 modal binding doesn't working

我有一个Bootstrap模式div:

<div class="modal fade" id="modalLoginData" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Login Data</h4>
        </div>

        <div class="modal-body">
            <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <label class="sr-only">Username</label>
                <input type="text" class="form-control" placeholder="Username" data-bind="value: username" />
            </div>   

            <div class="form-group col-lg-6 col-md-6 col-sm-12 col-xs-12">
                <label class="sr-only">Password</label>
                <input type="password" class="form-control" placeholder="Password" data-bind="value: password"  />
            </div>   

            <div class="form-group col-lg-6 col-md-6 col-sm-12 col-xs-12">
                <label class="sr-only">Repeat your password</label>
                <input type="password" class="form-control" placeholder="Repeat your password" data-bind="value: repeatedPassword" />
            </div>   
            <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <label class="sr-only">Login</label>
            </div>
        </div>

        <div class="modal-footer">
            <button type="button" class="btn btn-success btn-sm" data-bind="click: confirmLoginData">Confirm</button>
            <button type="button" class="btn btn-default btn-sm" data-dismiss="modal" data-bind="click: cancelLoginData">Cancel</button>
        </div>
    </div>
</div>

我正在通过JS打开此模式。

好的,如果我将username属性设置为某个值...

function Model() {
    this.username = ko.observable("kiwanax");
}

...该值正确显示在该模态div 之外的span元素上...

<span data-bind="text: username"></span>

...但无法在上面的模式div中的该文本框上使用。

有人知道发生了什么吗?

谢谢!

正如其他人已经提到的那样,发布更完整的代码版本将大大有助于其他人为您提供帮助。 在不发布您编写的JavaScript的情况下,人们只能猜测您在做什么。

话虽如此,这是您的模态示例,其中剔除确实在模态内部以及模态外部都显示了用户名

http://jsbin.com/AFORuzAT/2/edit

$('#modalLoginData').modal();

function Model() {
    this.username = ko.observable("kiwanax");
    this.password = ko.observable();
    this.repeatedPassword = ko.observable();
    this.cancelLoginData = function () {
        console.log( 'cancel!' );
    };
    this.confirmLoginData = function () {
         console.log( 'confirm login data!' );
    };
}

ko.applyBindings(new Model());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM