0

我想将值表单弹出视图传递给父视图如何使用 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"
  });
},

如何在父视图中获取“最终”的值?

4

1 回答 1

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视图中可用this["final_var"].

于 2013-02-13T04:58:37.873 回答