JQuery和Knockout绑定在一起不能正常工作

时间:2012-12-19 07:24:16

标签: jquery knockout.js

我有一个关于淘汰赛结合jQuery的问题。如果我只使用Knockout,程序运行正常,但只要我在jQuery中绑定它就不再工作了。第二页未显示。

这就是我绑定所有需要的东西:

<script type="text/javascript" src="../../Scripts/upshot.min.js"></script>
<script type="text/javascript" src="../../Scripts/Upshot_Timeworx.js"></script>
<script type="text/javascript" src="../../Scripts/knockout-2.2.0.js"></script>
<script src="../../Scripts/jquery.mobile-1.2.0.js" type="text/javascript"></script>


var masterViewModel = {

        loginVM: ko.observable(),
        startVM: ko.observable(),
        projectStartVM: ko.observable()

    };

    var LoginVM = function () {
        //Some Code
    };

    var StartVM = function () {
         //Some Code
    };

    var ProjectStartVM = function () {
    //Some Code
    //That's how I open the next "Page"
    masterViewModel.loginVM(new LoginVM());
    ko.applyBindings(masterViewModel);

LoginVM:

var LoginVM = function () {
            var self = this;
            self.mandant = ko.observable();
            self.user = ko.observable();
            self.password = ko.observable();
            self.showDetails = function () {

                if ((self.user() == "Gregor") && (self.password() == "gregrech")) {
                    masterViewModel.loginVM(null);
                    masterViewModel.startVM(new StartVM());
                }
                else {
                    alert("Username oder Passwort falsch");
                }

            };
        };

有谁知道我的问题是什么?

1 个答案:

答案 0 :(得分:0)

这似乎有效,不确定你实际要求的是什么。它通过单击来绑定用户名/密码框以继续执行该功能。

User:<input type="text" data-bind="value: user"/>
Password:<input type="password" data-bind="value: password"/>
<input type="button" data-bind="click: showDetails" value="Show"/>

http://jsfiddle.net/Maslow/mmMcs/

var LoginVM = function () {
  var self = this;
  self.mandant = ko.observable();
  self.user = ko.observable();
  self.password = ko.observable();

  self.showDetails = function () {

    if ((self.user() == "Gregor") && (self.password() == "gregrech")) {
      masterViewModel.loginVM(null);
      masterViewModel.startVM(new StartVM());
    } else {
      alert("Username oder Passwort falsch");
    }

  };
};
var masterViewModel = {

  loginVM: ko.observable(),
  startVM: ko.observable(),
  projectStartVM: ko.observable()

};


var StartVM = function () {
  alert('success');
};

ko.applyBindings(new LoginVM());