2012-03-21 60 views
1

Dojo版本是1.7.2當JsonRestStore有新數據時更新DataGrid

我有一個DataGrid,裏面充滿了來自MemoryStore的數據。它工作正常,但在商店中更新對象時,網格中的數據不會更新。

這是網格和實體店如何連接:

formStore = Observable(new MemStore()); 
formGrid = new DataGrid({ 
    store:ObjectStore({objectStore:formStore}), 
    query:{id:"*"}, 
    structure:[ 
     { name:" ", field:"pending", width:"2em", 
     formatter:function (count, rowIdx, cell) { 
      return '<div style="font-size: smaller; text-align: right;">' + count + '</div>'; 
     } 
     }, 
     { name:" ", field:"name", width:"auto", 
     formatter:function (formName, rowIdx, cell) { 
      return '<div style="white-space: nowrap;">' + formName + '</div>'; 
     } 
     } 
    ] 

}, "formGrid"); 

,我有一個函數,在商店的更新數據:

function updateForms() { 
    require(["dojo/_base/xhr", "dojo/_base/array", "dojox/grid/DataSelection"], 
       function (xhr, array, DataSelection) { 
        xhr.get({ 
        url:"services/jsonrest/form/", 
        content:{ id:"all" }, 
        handleAs:"json", 
        load:function (forms, io) { 
         array.forEach(forms, function(form, idx) { 
          formStore.notify(form, form.id); 
         }); 
        } 
        }); 
       }); 
} 

商店是否爲空,此功能運行時,這些項目將顯示在DataGrid中,但是一旦項目位於網格中,它們就不會更新。這是一個測試系統,是每次調用時Form對象變化的一部分。

我最終什麼事做的是改變服務器上的方法來返回所有項目的所有時間,然後JavaScript函數是像這樣:

function updateForms() { 
    require(["dojo/_base/xhr", "dojo/_base/array", "dojox/grid/DataSelection"], 
       function (xhr, array, DataSelection) { 
        xhr.get({ 
        url:"services/jsonrest/form/", 
        content:{ id:"all" }, 
        handleAs:"json", 
        load:function (forms, io) { 
         // reset all the items in the DataGrid 
         formGrid.setItems(forms); 
        } 
        }); 
       }); 
} 

這個作品也是如此。選擇被保留並且DataGrid不閃爍。但它有點失敗的目的。

我發現這個article但沒有意義。我嘗試了很多東西,沒有任何工作。在本文中,使用舊的dojo.connect語法代替新的dojo.on

我敢肯定,只是在某處丟失了一處細節。

謝謝你的幫助。

+0

您是否嘗試調用網格刷新? formGrid.refresh() – 2012-03-21 19:05:15

+0

顯然formGrid.refresh()不是一個函數。我在FireBug中遇到了一個錯誤,告訴我如此。 – 2012-03-22 07:05:41

+0

它可能在後面的dojo版本中被刪除。你在做什麼應該在理論上工作 - 我可以建議的唯一的另一件事是做一個抓取並確保你的商店確實被更新了。 – 2012-03-22 14:28:52

回答

0

在最新版本的dojo中,已經刪除了DataGrid的publicrefresh()方法。您可以使用formGrid._refresh()訪問私人會員

請注意,由於某些原因,他們必須刪除公共職能,這違背了OOPS的理念。

作爲一般性建議,在沒有找到其他解決方案的情況下,請嘗試在單行模式的螢火蟲控制檯中輸入formGrid.。當你輸入.時,你會得到所有對象的所有成員和屬性列表,包括所有的公共對象(通常在開始時不會有_)和所有私有對象(通常在開頭是_)。

如果它在螢火蟲中不起作用,請嘗試使用卓越的鉻版控制檯。