我有一个带有 json 类型数据存储的 dojo 数据网格。我已经完成了显示从 mysql 数据库中获取的数据。我想做的是允许分页,使行数据可编辑并将编辑后的数据更新到数据库中。这是我到目前为止所得到的:
<style type="text/css">
@import "dojoroot/dijit/themes/claro/claro.css";
@import "dojoroot/dojo/resources/dojo.css";
@import "dojoroot/dojox/grid/enhanced/resources/claro/EnhancedGrid.css";
@import "dojoroot/dojox/grid/enhanced/resources/EnhancedGrid_rtl.css";
</style>
<script type="text/javascript" src="dojoroot/dojo/dojo.js" data-dojo-config="async: true, isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript">
require(["dojo/store/JsonRest"], function(JsonRest){
myStore = new JsonRest({target:"jsonExample.php"});
});
require([
"dojox/grid/EnhancedGrid",
"dojox/grid/enhanced/plugins/Pagination",
"dojo/data/ObjectStore",
"dojo/domReady!",
"dijit/form/Form"
], function(DataGrid, ObjectStore){
grid = new DataGrid({
store: dataStore = ObjectStore({objectStore: myStore}),
editable:true,
structure: [
{name:"ID", field:"writer_id", width: "50px"},
{name:"Writer's Name", field:"writer_name", width: "200px", editable: true},
{name:"Writer's Email", field:"writer_email", width: "200px", editable: true}
],
//declare usage of plugins
plugins: {
pagination: {
sizeSwitch: false,
defaultPageSize: 10
}
},
}, "target-node-id"); // make sure you have a target HTML element with this id
grid.startup();
});
</script>
jsonExample.php 从 mysql 获取数据并将数据转换为 json 格式
<?php
$db=mysql_connect("localhost","root","") or die("could not connect to mysql server");
mysql_select_db("demo",$db) or die("could not connect to database");
$query="SELECT * FROM writers";
$resultSet=mysql_query($query,$db);
$arr = array();
while($row = mysql_fetch_object($resultSet)){
$arr[] = $row;
}
$jsonStr = json_encode($arr);
mysql_close($db);
echo "{$jsonStr}";
?>
我在我的 javascript 控制台中收到以下错误 this.option is undefined this.defaultPage=this.option.defaultPage>=1?parseInt(this.option.defaultPage,10):1;