[英]Transfer values from one page to another Page backbone Js
我想將值表單彈出視圖傳遞給父視圖,如何使用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"
});
},
如何在父視圖中獲得“最終”的價值?
我不確定最佳做法,但是一種方法是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
之后,使用this["final_var"]
在parent
視圖中可以使用final
值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.