[英]Call a new View from another View in Backbone
我是JS和Mongo / Mongoose / Express / Node / Backbone / Require堆栈的完全新手......所以有很多需要学习的内容,我完全有可能在这里错过了一些东西。 但是我试图存储提交表单的结果,然后如果保存操作成功则将用户移动到不同的视图,所以我的View看起来像这样:
define(['CoreView', 'text!templates/profile.html', 'models/Account'],
function(CoreView, profileTemplate, Account) {
var profileView = CoreView.extend({
el: $('#content'),
events: {'submit form': 'update'},
template: _.template(profileTemplate),
update: function() {
/*
* Gather the form data... then:
*/
$.post('/accounts/' + this.model.get('_id'),
{data: formData},
function(response) {
if (response == 'OK') {
$.get('/#index'); // NO CHANGE???
} else {
console.err('Save Failed :(');
}
});
return false;
},
render: function() {
if (this.model.get('_id') !== 'me') {
this.$el.html(this.template(this.model.toJSON()));
}
return this;
}
});
return profileView;
});
现在很可能我错过了路由中的一些机制,我可以指定这种事情,任何关于为什么这不起作用的建议或者更好的解决方案是受欢迎的。
$.get()
发出一个页面的GET请求 - 它没有做任何事情来“将用户移动到另一个视图”。 要做到这一点,你可以使用:
document.location.href = /#index`
或者如果你有Backbone.Router
或类似的更好的解决方案:
router.navigate('index')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.