변경이 발생하면 새보기를 렌더링 할 수 있도록 다른보기의 변경 내용을 기반으로보기를 제거하려고합니다. 현재 검색 버튼을 클릭하면보기를 제거하고 다른보기를 추가하려는 컨테이너보기가 있습니다. 렌더링은 컨테이너 뷰에서 발생합니다 (모델로 뷰를 렌더링하고 템플릿을 추가 함). 그러나 컨테이너보기에서 검색보기의 변경 사항을 수신 대기 또는 허용하는 방법을 알지 못합니다. 컨테이너보기를 작성한 이유는 경로를 변경하지 않기 때문에 매개 변수가/search에서 변경 될 수 있기 때문입니다. to/page와 결과를 보여 주지만 컨테이너 뷰가 제거되고 라우터가 이것을 제어하더라도 라우터가 변경 사항을들을 수 있도록하려면 어떻게해야 하는가?다른보기의 변경 사항을 기반으로보기를 제거하는 방법은 무엇입니까? 백본
라우터를 사용하거나 컨테이너보기를 사용하여 방향을 청취하는 것은 변경 이벤트 수신 방법을 알아야하기 만하면됩니다.
define([
'jquery',
'underscore',
'backbone',
'models/search',
'text!templates/search.html',
], function($, _, Backbone, SearchM, SearchT){
var Search = Backbone.View.extend({
//model: SearchM,
el: $("#Sirius"),
events: {
'submit #searchMusic': 'search'
},
initialize: function() {
this.listenTo(this.model, 'change:display', this.displayChanged);
},
displayChanged: function() {
console.log('display changed');
},
search: function (e) {
e.preventDefault();
var that = this;
//post instance to the server with the following input fields
that.model.save({
channel: $('#channel').val(),
week: $('#week').val(),
year: $('#year').val(),
filter: $('#filter').val()
},{success: that.storeMusic(that) });
// on success store music on client-side localStorage
},
storeMusic: function (that, response, options) {
console.log('store');
//create new instance of the localStorage with the key name
that.model.localStorage = new Backbone.LocalStorage("music");
var that = this;
that.clearLocalStorage(that);
that.saveToLocalStorage(response, that);
},
clearLocalStorage: function (that) {
console.log('clear');
//removes the items of the localStorage
that.model.localStorage._clear();
//pops out the first key in the records
that.model.localStorage.records.shift();
},
saveToLocalStorage: function (response, that) {
console.log('save');
console.log(that);
that.model.save({music: response}, {success: that.nextPage(that)});
},
nextPage: function (that) {
console.log('entered next page');
that.model.set('display', true);
}
});
return Search;
});
단점이란 무엇입니까? 또한, 결국에는 렌더링 할 다른 뷰와 그 뷰의 페이지를 갖게 될 것이므로이 방법이 문제가됩니까? – Lion789
페이지 맨 위에 _.extend 부분을 포함 할 때 오류가 발생합니다 ... – Lion789
어떤 오류가 발생합니까? '_.extend'를 호출하기 전에 underscore.js를 포함시켜야합니다. – pawel