저는 백본에서 약간의 CRUD 앱을 만들고 있는데,보기간에 리디렉션 할 필요가 조금 있습니다. 내 앱은 다른보기가 렌더링되는 layout
보기와 라우터로 구성됩니다. 여기있다 :이벤트에서 다른보기를 리디렉션하거나 렌더링합니다.
var router = Backbone.Router.extend({
routes: {
'': 'home',
'resumes/:id': 'showResume'
},
home: function() {
// renders a index view with my collection
this.layout.render(new ResumeList({collection: resumes});
},
showResume: function() {
if (!this.fullResume) {
this.fullResume = new FullResume({model: new Resume()});
}
// allowing to navigate via url with model id
this.fullResume.model.set('id', id).fetch({
context: this,
success: function() {
this.layout.render(this.fullResume);
}
});
}
});
그런 다음 내 FullResume
보기에 내가 모델을 파괴 delete
이벤트를 가지고있다. 여기 간다 :
var FullResume = Backbone.View.extend({
// tagName and other stuff
events: {
// other events
'click #delete': 'deleteResume'
},
// initialize, render and other functions
deleteResume: function() {
this.model.destroy({
success: function (res) {
console.log('DELETE model' + res.toJSON().id);
},
error: function() {
console.log('Failed to DELETE');
}
});
}
});
기능은 위에서 완벽하게 작동하고 모델을 삭제,하지만 난 곳 수동으로 이동 될 때까지 모델을 삭제 한 후 여전히 그것의보기에 남아 있습니다. 조금 읽은 후이 이벤트가 끝난 후 기본보기를 렌더링하거나 리디렉션하는 방법을 관리하려고했지만 많이 성공하지 못했습니다.
라우터가 코드에서 공유되지 않으면 'Backbone.history.navigate (...)'를 사용하여 직접 탐색 할 수 있습니다. –