通过ID获取声明性dojo数据网格
Get declarative dojo datagrid by ID
我在按ID访问声明创建的数据网格时遇到问题,因此无法设置其数据存储。
这是我的代码,但树返回为未定义。
提前感谢您的帮助。
<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.10.3/dojo/dojo.js" data-dojo-config="async: true"></script>
</head>
<body>
<table data-dojo-id="myTree" dataType="dojox.grid.TreeGrid" summary="This is a test">
<thead>
<tr>
<th field="a" width="200px">A</th>
<th field="items" aggregate="sum" itemAggregates="count">
<table>
<thead>
<tr>
<th field="name" width="200px">Name</th>
<th field="count" width="200px">Count</th>
</tr>
</thead>
</table>
</th>
</tr>
</thead>
</table>
</body>
<script>
require(["dijit/registry", "dojo/data/ItemFileReadStore"], function( Registry, ReadStore ) {
var store = new ReadStore();
var tree = Registry.byId("myTree");
console.log(tree);
// tree.setStore( store );
});
</script>
</html>
您的代码有几个问题导致您的问题。
dataType
不是一个东西;您想要data-dojo-type
(可能会将其与不推荐使用的dojoType
混淆)- 设置
data-dojo-id
会创建一个全局变量,而不是Dijit注册表的ID;改为设置id
- 您也从来没有在文档上实际运行过
dojo/parser
,所以即使解决了这些问题,您也不会得到真正的小部件
这里有一个固定的例子:
<body>
<table id="myTree" data-dojo-type="dojox/grid/TreeGrid" summary="This is a test">
...
</table>
</body>
<script>
require([
"dojo/parser",
"dijit/registry",
"dojo/data/ItemFileReadStore",
"dojox/grid/TreeGrid"
], function(parser, registry, ReadStore) {
parser.parse();
//var store = new ReadStore(...);
var tree = registry.byId("myTree");
console.log(tree);
// tree.setStore( store );
});
</script>
相关文章:
- 用程序搜索JQuery数据表中的文本
- 要求输入在数据列表中
- 正在将数据主题添加到所有项目
- 函数参数中的数据与指定变量之间的任何性能差异
- 在VanillaJS中模拟模型双向数据绑定
- CSS-如何定位内容数据标题
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 序列化数据属性中对象的最可靠方法
- 如何将JSON数据导入我的ejs模板
- 不显示带有本地json文件数据的谷歌地图脚本
- 如何将json数据显示为html
- 画布数据到图像
- 使用jquery将mysql数据获取到新的表行中
- 使用html中的外部javascript进行数据验证
- 有时数据是't显示在浏览器中
- React中的数据集表示
- Angular只从数组中获取所需的数据
- 无法将数据从firebase获取到我的html页面
- YUI3 IO实用程序是否可以根据给定的内容类型标头值自动序列化数据