0

我有一个关于淘汰赛与 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);

登录虚拟机:

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");
                }

            };
        };

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

4

1 回答 1

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());
于 2013-02-01T18:33:31.273 回答