Backbone - 从视图完全更改模型,包括它的参考

Backbone - Completely change model from View including it's reference

我想知道是否可以完全更改模型,不仅是它的值,而且是对已经初始化的视图的实际引用。我看过 this question 但它仅指模型值。

我创建了一个可重用视图(呈现 Google 地图),它被其他不同的视图使用,不是通过将可重用模块创建为子视图而是导航到 URL显示全屏地图,这是我视图的一个实例。

此地图视图接收初始化模型,稍后在此视图中进行修改,并且由于它是相同的模型引用,它还会更新调用(请求导航到)地图的视图模型,我正在调用来自我的路由器的所有视图,它知道创建了哪些视图并保存对所有视图的引用,因此我可以通过这种方式在视图之间共享模型。

var myRouter= Backbone.Router.extend({
        routes : {"viewA(/)" : "invokeViewA"
        "viewA/map" : "invokeViewAMap"
        //... same with ViewB
        },
        //...
        invokeViewAMap : {
            if (mapViewInstance){
                //if the map already exists i want to update its model with the viewAinstance.model
            } else{
                 //there is no map view yet so let's create it and send the model i need updated later on
                 mapViewInstance = new AddressFinderMapView({model : viewAInstance.model});
            }
        },
        invokeViewBMap {
          //similar to the above but using viewBInstance's model
        }
    });
    
var AddressFinderMapView = Backbone.View.extend({
  //initialize function
  //render function
  //init google map
  events : {"click button" : "updateModelWithAddress"},
  updateModelWithAddress : function(){
    //Here is where i need to update the model values, of the model that this view has received, so far it works with the model that was sent on initialization
    this.model.set({
      //latitude and longitude from the map
    })
  }
});

其他想法:

只需将新模式分配给视图实例的 model 属性,例如:

viewInstance.model = newModelInstance;