2010-12-14 49 views
1

我遇到了使我的dojo增強網格可編輯的問題。 目前,我可以雙擊網格單元格,我可以更改值,但是當我再次按下Enter或嘗試離開單元格(即將新值保存到網格)時,我收到了「ItemFileWriteStore中的斷言失敗「我的螢火蟲錯誤。Dojo增強網格可編輯問題

下面是我的源代碼:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
    <head> 
    <style type="text/css"> 
     body, html { font-family:helvetica,arial,sans-serif; font-size:90%; } 
    </style> 
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css" /> 
    <style type="text/css"> 
     @import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojox/grid/resources/Grid.css"; 
     @import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojox/grid/resources/claroGrid.css"; 
     .dojoxGrid table { margin: 0; } 
    </style> 
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js" djConfig="parseOnLoad: true"> 
    </script> 

    <script type="text/javascript"> 
     dojo.require("dojox.grid.EnhancedGrid"); 
     dojo.require("dojo.data.ItemFileWriteStore"); 
     dojo.require("dojox.grid.cells._base"); 

     dojo.addOnLoad(function() { 

      var layoutabc = 
      [[ 
       { 
        field: "title", 
        name: "TitleofMovie", 
        width: "300px", 
        editable: true 
       }, 
       { 
        field: "year", 
        name: "Year", 
        width: "200px", 
        editable: true 
       }, 
       { 
        field: "producer", 
        name: "Producer", 
        width: "auto", 
        editable: true, 
        type: dojox.grid.cells.Cell 
       } 
      ]]; 


      var mystore = new dojo.data.ItemFileWriteStore({ 
       url: "movies.json" 
      }); 

      // create a new grid: 
      var grid = new dojox.grid.EnhancedGrid(
       { 
        query: {}, 
        store: mystore, 
        structure: layoutabc 
       }, 
       document.createElement("div") 
      ); 
      dojo.byId("gridDiv").appendChild(grid.domNode); 

      grid.startup(); 
     }); 
    </script> 
</head> 

<body class="claro"> 
    <div id="gridDiv" style="width: 800px; height: 400px;"> 
    </div> 
</body> 

這是我movies.json的內容(數據的內容很奇怪,我知道):

{ 
    items: 
    [ 
     { 
      title: "Africa", 
      year: "continent", 
      producer: "Katia Lund" 
     }, 
     { 
      title: "Kenya", 
      year: "country", 
      producer: "Christine Jeffs" 
     }, 
     { 
      title: "Mombasa", 
      year: "city", 
      producer: "Ridley Scott" 
     } 
    ] 
} 
+0

附加信息:如果我更改爲使用DataGrid而不是EnhancedGrid,那麼整個事情就會起作用... – Hery 2010-12-14 06:25:51

+0

您是如何解決的? 我有插件設置在「{nestedSorting:true}」,並添加在我的代碼(在添加按鈕)這部分變量gPlugins =「{nestedSorting:true}」; grid.plugins = gPlugins;但沒有什麼變化;當我刷新表格時不要添加該行。 – 2011-10-26 14:26:44

+0

@francesco:我將'plugins'屬性傳遞給了EnhancedGrid本身的構造函數。雖然我懷疑它會有所作爲,但你應該嘗試一下。如果它不能解決你的問題,你應該問一個新的問題,因爲這個問題被問及了一段時間,現在使用的dojo版本可能會有所不同。 – Hery 2011-10-27 02:34:25

回答

1

問題已解決。原來我需要爲EnhancedGrid對象定義「插件」屬性,即使它只是一個空對象。一旦確定了它的正常工作。

0

我認爲問題在於您的商店不包含任何標識符,因此當網格試圖寫入商店時,它無法知道應該寫入哪個條目。

我會通過編輯movies.json的反應,也許是這樣開始:

{ 
    identifier:"id", 
    items: 
    [ 
     { 
      id:1 
      title: "Africa", 
      year: "continent", 
      producer: "Katia Lund" 
     }, 
     { 
      id:2 
      title: "Kenya", 
      year: "country", 
      producer: "Christine Jeffs" 
     }, 
     { 
      id:3 
      title: "Mombasa", 
      year: "city", 
      producer: "Ridley Scott" 
     } 
    ] 
} 

注意,您不必包括佈局列表中的id字段,這將是可訪問無論如何。此外,正如標識符所暗示的,它必須是商店中每個商品的唯一值,否則它將無法初始化。

+0

試過這個,它仍然不起作用:( 嘗試添加標籤,以及不工作:( – Hery 2010-12-14 04:58:08