[英]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.