0

大家好我一直在研究骨幹應用程序,圖像被添加和現有的圖像被刪除或編輯。現在我使用路由器的各種部分,如畫廊,表格,但是當我在畫廊編輯的東西回到形式和回來我沒有得到我以前做的變化。相反,它顯示舊數據。我需要刷新我的意思是CTRL + F5來查看那些不好的變化。如何在獲取新數據之前清除骨幹網集合?

我試過.clear和.reset它重置集合和模型,但不影響集合內的數據。任何人都可以幫助我,我哪裏出錯了。

下面是集合代碼和型號:

var GalleryImage = Backbone.Model.extend({}); 

var GalleryImages = Backbone.Collection.extend({ 
model : GalleryImage, 
url: '######', 
initialize : function(){ 


    this.reset(); 
    if(this.reset()) 
    { 
     console.log("model reset", GalleryImage.cid) 
    }else{ 
     console.log("model not set") 
    } 

    this.on("reset", this.loadImagesView,this); 
    this.on("error", this.errorMessage,this); 
     //console.log(GalleryImages.get(0)) 

}, 
loadImagesView : function(){ 
    //console.log(this); 
    //console.log(this.CollView.$el); 
    if(!this.CollView){ 
     this.CollView = new GalleryImagesView({collection:this}) 
    } 
     this.CollView.render(); 

}, 
errorMessage : function(){ 
    jQuery('#imageBlocksDiv').html('<span id="noMsg"><h4>No images to display.</h4></span>'); 
} 

});

和路由器是:

initGallery : function(){ 

      jQuery('#invset').hide(); 
      jQuery('#imagelist').children().eq(0).append(jQuery('.floor_img').find('#box').css({'z-index':'1','position':'relative','margin-top':'0px','margin-left':'0px'})); 
      pinterest(undefined); 
    jQuery("#box").show(); 
      jQuery('#invset').hide(); 
      jQuery('#inventorycontent').hide(); 
    jQuery("#boxnews").hide(); 
    jQuery("#boxzip").hide(); 
    jQuery(".select").attr('style','display:block'); 
    jQuery(".select").attr('id','ugallerygal'); 
    jQuery(".pagetitle").html('Gallery'); 
    var that = this,projectId = jQuery('#ugallerygal').val(); 
    jQuery('#imageBlocksDiv').html(''); 
    var imgObj = new GalleryImages(); 

    //this.reset(imgObj); 

    imgObj.fetch({data: jQuery.param({projectId: projectId, add:true, reset:true}), success:function(){ 
         console.log(imgObj) 
         imgObj.trigger("reset"); 
      }, 
      error : function(){ 
      imgObj.collection.trigger("error"); 
      } 
    }); 

}, 

這不僅我有一節,當圖像用戶點擊圖片打開,並通過點擊圖像的任何地方可以放置一個點,並在添加詳細信息點,我在解析存儲,但更改的值得到保存,但當我回到圖像時,顯示較舊的位置和數字圖像,而不是更新的一個和更新點存儲在解析。我猜這個問題對於兩個國家來說都是一樣的,所以一個解決方案對所有人都適用。

任何幫助深表謝意。感謝提前

感謝你,桑托斯 Upadhayay

回答

0

問題可能是帶復位的順序,並增加復位聽衆。嘗試改變

this.reset(); 
if(this.reset()) 
{ 
    console.log("model reset", GalleryImage.cid) 
}else{ 
    console.log("model not set") 
} 

this.on("reset", this.loadImagesView,this); 
this.on("error", this.errorMessage,this); 

this.on("reset", this.loadImagesView,this); 
this.on("error", this.errorMessage,this); 
this.reset(); 
if(this.reset()) 
{ 
    console.log("model reset", GalleryImage.cid) 
}else{ 
    console.log("model not set") 
} 
+0

我試過,但,這並不影響是存在的,因爲我們編輯任何其他方式和其他的鏈接保存的東西點擊,但網頁不刷新,當再次點擊回鏈接顯示舊的東西 –