簡體   English   中英

將值從一頁轉移到另一頁主干Js

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM