为什么dojo网格需要json数据源中的name列

vuv7lop3  于 2022-12-16  发布在  Dojo
关注(0)|答案(2)|浏览(232)

在下面的示例中,只有当JSON数据包含名称列时,数据才会显示在网格中-〉第一个网格显示数据,第二个不显示。
为什么会这样呢?

**索引.html:**dojo网格

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dijit/themes/tundra/tundra.css" />
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/resources/dojo.css" />
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojox/grid/_grid/tundraGrid.css">
    <script type="text/javascript" 
            src="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js" 
            djConfig="parseOnLoad: true, isDebug: true">
    </script>

    <script type="text/javascript">
      dojo.require("dojo.parser");
      dojo.require("dojox.grid.Grid");
      dojo.require("dojo.data.ItemFileReadStore");
    </script>

  </head>
  <body class="tundra">
   <span dojoType="dojo.data.ItemFileReadStore" 
            jsId="withNameStore" 
            url="WithNameColumn.json"
            clearOnClose="true">
    </span>
    <table id="withNameGrid"
           dojoType="dojox.grid.Grid" 
           store="withNameStore"
           clientSort="true"
           style="width: 20em; height: 20em;">
        <thead>
           <tr>
              <th field="ID" >ID</th>
              <th field="test">Test</th>
           </tr>
        </thead>
    </table>
    <span dojoType="dojo.data.ItemFileReadStore" 
          jsId="withoutNameStore" 
          url="WithoutNameColumn.json"
          clearOnClose="true">
    </span>
    <table id="withoutNameGrid" 
           dojoType="dojox.grid.Grid" 
           store="withoutNameStore"
           clientSort="true"
           style="width: 20em; height: 20em;">
        <thead>
           <tr>
              <th field="ID" >ID</th>
              <th field="test">Test</th>
           </tr>
        </thead>
    </table>
  </body>
</html>

具有名称列.json:

{
  "identifier":"ID",
  "label":"test",
  "items":
    [{"ID":2,"name":"name1","test":"dog"},
     {"ID":3,"name":"name2","test":"cat"},
     {"ID":4,"name":"name3","test":"mouse"}]
}

没有名称列.json:

{
  "identifier":"ID",
  "label":"test",
  "items":
    [{"ID":2,"test":"dog"},
     {"ID":3,"test":"cat"},
     {"ID":4,"test":"mouse"}]
}
w41d8nur

w41d8nur1#

只需在元素中添加一个查询属性,如下所示:
〈表查询="{ID:'*'}”...〉
这是因为从数据存储请求数据时将执行查询

zfciruhq

zfciruhq2#

名称列不是必需的,但您确实需要数据存储区中的属性与网格中的列名之间的Map。这是在定义网格“布局”时完成的,“布局”中的“字段”属性是数据存储区中的列的名称(确切地说是属性的名称),“布局”中的“名称”属性是网格中的列名。

gridLayout = [{
  defaultCell: {
    width: 8,
    editable: true,
    type: dojox.grid.cells._Widget,
    styles: 'text-align: right;'
  },
  rows: [{
      name: 'Id',
      field: 'id',
      editable: false /* Can't edit ID's of dojo.data items */
    },
    {
      name: 'Date',
      field: 'col8',
      width: 10,
      type: dojox.grid.cells.DateTextBox,
      formatter: formatDate,
      constraint: {
        formatLength: 'long',
        selector: "date"
      }
    },
    {
      name: 'Priority',
      styles: 'text-align: center;',
      field: 'col1',
      type: dojox.grid.cells.ComboBox,
      options: ["normal", "note", "important"],
      width: 10
    },
    {
      name: 'Mark',
      field: 'col2',
      width: 3,
      styles: 'text-align: center;',
      type: dojox.grid.cells.CheckBox
    },
    statusCell,
    {
      name: 'Message',
      field: 'col4',
      styles: '',
      width: 10,
      type: dojox.grid.cells.Editor,
      editorToolbar: true
    },
    {
      name: 'Amount',
      field: 'col5',
      formatter: formatCurrency,
      constraint: {
        currency: 'EUR'
      },
      widgetClass: dijit.form.CurrencyTextBox
    },
    {
      name: 'Amount',
      field: 'col5',
      formatter: formatCurrency,
      constraint: {
        currency: 'EUR'
      },
      widgetClass: dijit.form.HorizontalSlider,
      width: 10
    }
  ]
}];

相关问题