简体   繁体   English

将值从一页转移到另一页主干Js

[英]Transfer values from one page to another Page backbone Js

I Would like to pass a value form popup view to parent view How it possible by using Backbone JS 我想将值表单弹出视图传递给父视图,如何使用Backbone JS

I am done the code like this 我完成了这样的代码

for popup the view 弹出视图

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"
  });
},

And from popup page submit button we have done the following code 从弹出页面的提交按钮,我们完成了以下代码

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"
  });
},

How I can get the value of "final" in the parent view ? 如何在父视图中获得“最终”的价值?

I'm not sure about the best practice, but one way would be, pass this reference from the parent view to the popup page as: 我不确定最佳做法,但是一种方法是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

},

And in the popup view: 并在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
},

And after clickClose is executed, value of final will be available in the parent view with this["final_var"] . 在执行clickClose之后,使用this["final_var"]parent视图中可以使用final值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM