我想将值表单弹出视图传递给父视图如何使用Backbone JS
我完成了像这样的代码
用于弹出视图
loadPopupGeoBox: function () {
var newUserlist = new TripsdetailsModel();
selectModel = newUserlist;
var that = this;
require(['views/searchlocationek'], function (view) {
var view = new view({ model: selectModel});
view.open();
that.addview = view;
});
$('#popup_geocode').fadeIn("slow");
$("#container").css({
"opacity": "0.3"
});
},
从弹出页面提交按钮我们已完成以下代码
clickClose: function() {
require(['views/trip'], function (view) {
var view1 = new view();
view1.openfilter(final);
});
$('#popup_geocode').fadeOut("slow");
$("#container").css({ // this is just for style
"opacity": "1"
});
},
如何在父视图中获取“final”的值?
答案 0 :(得分:1)
我不确定最佳做法,但有一种方法是,将this
引用从父视图传递到popup
页面:
loadPopupGeoBox: function () {
// existing code
var $this = this;
require(['views/searchlocationek'], function (view) {
var view = new view({
model: selectModel,
parent_view: $this
});
});
// existing code
},
在popup
视图中:
clickClose: function() {
// storing this reference to be used in the require call back
var $this = this;
require(['views/trip'], function (view) {
// existing code
// set the value of the final variable on the parent_view with
$this.options.parent_view["final_var"] = final;
});
// existing code
},
执行clickClose
后,final
视图中parent
的{{1}}值将会显示{/ 1}}。