Php 将编码的JSON加载到Dojo网格中

Php 将编码的JSON加载到Dojo网格中,php,mysql,json,dojo,Php,Mysql,Json,Dojo,我在用php编程, 我想获取我拥有的数组(从mysql结果集中提取),将其转换为JSON,然后在dojox.grid.DataGrid中使用它 我从他那里得到了一个主意 我在数组(在一个名为getJSON.php的文件中)上使用了以下内容 然后我尝试这样做(在我的主页上): 其他一切都与Dojo文档指定的完全相同。 网格显示,但不加载数据,而是写入对不起,发生了错误 有人知道原因吗?希望我给了你足够的时间继续下去。我没有为此使用ItemFileWriteStore!自Dojo1.6以来,它们发生

我在用php编程, 我想获取我拥有的
数组
(从mysql结果集中提取),将其转换为
JSON
,然后在
dojox.grid.DataGrid
中使用它

我从他那里得到了一个主意

我在
数组
(在一个名为
getJSON.php
的文件中)上使用了以下内容

然后我尝试这样做(在我的主页上):

其他一切都与Dojo文档指定的完全相同。 网格显示,但不加载数据,而是写入
对不起,发生了错误


有人知道原因吗?希望我给了你足够的时间继续下去。

我没有为此使用ItemFileWriteStore!自Dojo1.6以来,它们发生了很大的变化,所以您可能看到了一些不最新的东西

请尝试以下代码:

//加载必要的组件(这是带有AMD的dojo)

require([“dojo/aspect”,“dojo/_base/lang”,“dojox/grid/DataGrid” 、dojo/dom、dojo/store/JsonRest、dojo/data/ObjectStore、, “dojo/domReady!”

函数(aspect、lang、DataGrid、dom、JsonRest、ObjectStore){//将组件映射到变量

var store = new JsonRest({    
      target: "getJSON.php" // Use a URL that you can open up in a browser.
  });


/*layout for the grid, you will have to adapt this to your columns !!!*/
var layout = [[
  {'name': 'Filename', 'field': 'documentName', 'width': '300px'},
  {'name': 'Size', 'field': 'fileSize', 'width': '100px'},
  {'name': 'Id', 'field': 'id', 'width': '200px'}
]];

dataStore=ObjectStore({objectStore: store}); // Transform to Objectstore !

/*Now we create a new grid*/
var grid = new DataGrid({
    id: 'grid',
    store:dataStore, // Connect the store
    autoWidth:false,
    structure: layout, // Connect the layout
    rowSelector: '0px'});


grid.placeAt("yourTargetDivId"); // Has to be an existing DOM Element with id !
grid.startup(); // START IT !
}))

请先重复以下简单内容,尝试此代码:

echo'[{“id”:“1”,“fileSize”:“100kb”,“documentName”:“Lucian!”}, {“id”:“2”,“文件大小”:“900kb”,“文档名”:“Pew Pew!”}]


然后用你自己的JSON…

{code>{identifier:是坏的JSON。试试
{“identifier”
如果你有完整的JSON,你也可以用这样的工具来验证它:真的,有效的JSON还需要使用双引号(
)…但我想这可能不是问题所在..在我看来,您创建网格的方式可能有问题。您提供了结构定义吗?也许一点代码可能会有帮助..(尤其是创建网格的部分-网格)网格的创建是从链接attachedjust中获取的,这是为了参数。。这个:echo$ajax='{\'identifier\':\'db\u id\',\'items\':'.json\u encode($result)。'}';也不起作用
var store = new dojo.data.ItemFileWriteStore({ url: 'getJSON.php' });
var store = new JsonRest({    
      target: "getJSON.php" // Use a URL that you can open up in a browser.
  });


/*layout for the grid, you will have to adapt this to your columns !!!*/
var layout = [[
  {'name': 'Filename', 'field': 'documentName', 'width': '300px'},
  {'name': 'Size', 'field': 'fileSize', 'width': '100px'},
  {'name': 'Id', 'field': 'id', 'width': '200px'}
]];

dataStore=ObjectStore({objectStore: store}); // Transform to Objectstore !

/*Now we create a new grid*/
var grid = new DataGrid({
    id: 'grid',
    store:dataStore, // Connect the store
    autoWidth:false,
    structure: layout, // Connect the layout
    rowSelector: '0px'});


grid.placeAt("yourTargetDivId"); // Has to be an existing DOM Element with id !
grid.startup(); // START IT !