Transition between viewsModels

53 views
Skip to first unread message

Lucas Diego

unread,
Nov 22, 2016, 3:17:23 PM11/22/16
to KnockoutJS
Hello, I'm new to knockout and would like to ask for help if it were possible. I have a login screen that is executed by a viewmodel called login, and I would like that when the login was right the user was redirected to the dashboard screen would have how?


define(['ojs/ojcore', 'knockout', 'jquery'],
 function(oj, ko, $) {
  
    function LoginViewModel() {
      var self = this;
      
      self.userName = ko.observable();
      self.userPassword = ko.observable();

      self.login = function() {
         $.ajax({
          url: "myservice.com",
          type: "POST",
          contentType: "x-www-form-urlencoded",
          success: function (result) {
            console.log("Success: ");
            ko.applyBindings(new DashboardViewModel());
            var token = result.data[0].token;
            $.get('http://myservice' + token, function (response) {
              console.log(response.data);
            });
          },
          error: function (result) {
            console.log(result.responseText);
          }
        });
      };

    }
    return new LoginViewModel();
  }
);

define(['ojs/ojcore', 'knockout', 'jquery'],
 function(oj, ko, $) {
  
    function DashboardViewModel() {
      var self = this;
    }
    return new DashboardViewModel();
  }
);



Reply all
Reply to author
Forward
0 new messages