2010-12-14 51 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