나는 대답 귀하의 질문에 충분한 정보가 확실하지 않다,하지만이 작업을 수행 할 수있는 몇 가지 방법이 있습니다 :
공유 공통 모델. 설명하는대로 두 개의 뷰를 사용하여 모델을 구성하므로 모델 자체를 하위 뷰에 전달하고 뷰간에 변수를 전달하지 않고 하위 뷰에서 모델을 수정하는 것이 가장 쉽습니다.
var MyModel = Backbone.Model.extend({});
var ParentView = Backbone.View.extend({
// initialize the new model
initialize: function() {
this.model = new MyModel();
},
// open the pop-up on click
events: {
'click #open_popup': 'openPopUp'
},
openPopUp: function() {
// pass the model
new PopUpView({ model: this.model })
}
});
var PopUpView = Backbone.View.extend({
events: {
'change input#someProperty': 'changeProperty'
},
changeProperty: function() {
var value = $('input#someProperty').val();
this.model.set({ someProperty : value });
}
});
부모 이벤트를 트리거합니다. 어떤 이유로 당신은 단지 모델을 통해 값을 전달할 수없는 경우, 당신은 단지 이벤트가 부모에 대한 참조를 전달하고 트리거 할 수 있습니다 내가 정확하게이었다
var ParentView = Backbone.View.extend({
initialize: function() {
// bind callback to event
this.on('updateProperty', this.updateProperty, this);
},
updateProperty: function(value) {
// do whatever you need to do with the value here
},
// open the pop-up on click
events: {
'click #open_popup': 'openPopUp'
},
openPopUp: function() {
// pass the model
new PopUpView({ parent: this })
}
});
var PopUpView = Backbone.View.extend({
events: {
'change input#someProperty': 'changeProperty'
},
changeProperty: function() {
var value = $('input#someProperty').val();
this.options.parent.trigger('updateProperty', value);
}
});
완벽한을, 이벤트 트리거링 찾고. – Moustachio
도움이 되니 기쁩니다. 첫 번째 옵션 (모델 전달)은 이벤트 (모델의 "change : someProperty"이벤트)를 트리거하며, 제 의견으로는 더 간단 할 수 있습니다. – nrabinowitz