マイアプリinitが見え、私はすべてを試してみましたBackbone.history.navigateに動作していない
var $ = jQuery = require('jquery'),
Backbone = require('backbone'),
loginView = require('./views/login/LoginView'),
userActivitiesMainView = require('./views/dashboard/UserActivitiesMainView'),
mainDashboardView = require('./views/dashboard/MainDashboardView');
var Router = Backbone.Router.extend({
initialize: function (options) {
this.options = options;
this.currentView = null;
},
setCurrentView: function (view) {
if (this.currentView &&
typeof this.currentView.onClose != 'undefined') {
this.currentView.onClose();
}
this.currentView = view;
$('body').scrollTop(0);
},
routes: {
"": "home",
"login(/)": "home",
"dashboard(/)": "dashboard",
},
notFound: function() {
this.setCurrentView(null);
$('.div-main').html('<h2>Oops! Page not found. Please try going back from the browser.</h2>');
},
dashboard: function() {
"use strict";
var dashboard = new mainDashboardView();
this.setCurrentView(dashboard);
this.addSideBar();
this.addHeaderBar();
},
home: function() {
"use strict";
var login = new loginView();
this.setCurrentView(login);
},
addSideBar: function() {
var sidebar = new sidebarView();
//this.setCurrentView(sidebar);
},
//Function to add header
addHeaderBar: function() {
var header = new headerView();
//this.setCurrentView(header);
}
})
module.exports = Router;
var ret = Backbone.history.navigate('dashboard', true);
console.log(ret); // comes false for me
それは動作しませんが
編集:
私はビューで次のようにナビゲートしています:
events: function() {
return this.appendEvents({
'click #btnContinue': 'login'
})
},
login: function() {
var otp = this.$el.find('#otp').val();
var data = {
"mobile_number": sessionStorage.getItem('mobile_number'),
"otp": otp,
"name_of_user": "Vini",
"flag": "payment_link",
"title": "Pen and Pencil and rose",
"description": "You can write and erase and smile and pay",
"amount": "50.00",
"images": [
"ac19fa94-9f5f-48e0-93a7-53d5da616ac3",
"13da680e-6050-40e0-97c8-cc141d1439d9"
]
};
this.loginModel.set(data);
this.loginModel.save().then(function (response) {
console.log(response);
Cookies.set('API', response);
var ret = Backbone.history.navigate('#dashboard', { trigger: true});
console.log(ret);
})
}
予想される動作は何ですか?代わりに本当に何が起こっていますか?正確な問題は何ですか? –