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

ベスト プラクティスについてはよくわかりませんが、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 に答える