vaadin - 如何在聚合物 3 中实现 vaadin-grid-tree-column
问题描述
我在应用程序模板中有以下内容:
<vaadin-grid id="directory">
<vaadin-grid-tree-column path="name" header="Name"></vaadin-grid-tree-column>
</vaadin-grid>
Iron-ajax 在成功响应时调用以下命令:
getlist(request) {
var myResponse = request.detail.response;
console.log(myResponse);
this.$.directory.items = myResponse;
}
返回的数据是:
[
{
"name": "apps",
"fullpath": "/db/system/xqdoc/apps",
"children": [
{
"name": "xqDoc",
"fullpath": "/db/system/xqdoc/apps/xqDoc",
"children": [
{
"name": "modules",
"fullpath": "/db/system/xqdoc/apps/xqDoc/modules",
"children": [
{
"name": "config.xqm.xml",
"fullpath": "/db/system/xqdoc/apps/xqDoc/modules/config.xqm.xml"
},
{
"name": "xqdoc-lib.xqy.xml",
"fullpath": "/db/system/xqdoc/apps/xqDoc/modules/xqdoc-lib.xqy.xml"
}
]
}
]
}
]
}
]
出现apps
了,但是当我展开apps
节点时,xqDoc
节点不会出现。
- 我需要数据集中的其他数据吗?
- 我是否缺少一些需要的编码?
解决方案
我有解决办法。
<vaadin-grid id="directory" selected-items="{{selected}}">
<vaadin-grid-tree-column path="name" header="Name"item-has-children-path="hasChildren"></vaadin-grid-tree-column>
</vaadin-grid>
我使用 设置提供程序,connectedCallback
而不是使用iron-ajax
与服务器交谈。
connectedCallback() {
super.connectedCallback();
const grid = this.$.directory;
this.$.directory.dataProvider = function(params, callback) {
let url = "/exist/restxq/xqdoc/level" +
'?page=' + params.page + // the requested page index
'&per_page=' + params.pageSize; // number of items on the page
if (params.parentItem) {
url += '&path=' + params.parentItem.fullpath;
}
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var response = JSON.parse(xhr.responseText);
callback(
response.data, // requested page of items
response.totalSize // total number of items
);
};
xhr.open('GET', url, true);
xhr.send();
};
this.$.directory.addEventListener('active-item-changed', function(event) {
const item = event.detail.value;
if (item && item.hasChildren == false) {
grid.selectedItems = [item];
} else {
grid.selectedItems = [];
}
});
}
Web 服务返回树的一个级别:
{
"totalSize": 2,
"data": [
{
"name": "apps",
"fullpath": "/apps",
"hasChildren": true
},
{
"name": "lib",
"fullpath": "/lib",
"hasChildren": true
}
]
}
推荐阅读
- prolog - 如何访问 PROLOG 中的规则数据
- node.js - 我们可以在 angular6 项目中使用 node-gdal 包吗?
- javascript - 当代码使用 javascript 打开新窗口时,无法向包含 cookie 名称的浏览器发送响应
- php - 如何正确进行验证?
- r - 拆分默认值而不按列名排序
- python - 是否可以在不退出的情况下重新启动 Ipython 内核?
- php - 当我使用会话将值从一个页面发送到另一个页面时,出现以下错误
- swift - 在继续之前执行一个函数
- python - 从屏蔽的二维数组中提取平均值
- javascript - 如何将字典中的嵌套值更改为上层键