gpt4 book ai didi

java - Fuel UX 树递归问题

转载 作者:行者123 更新时间:2023-12-01 04:20:53 26 4
gpt4 key购买 nike

我有这个代码:

    <script>
$(window).load(function() {

var DataSource = function (options) {
this._formatter = options.formatter;
this._columns = options.columns;
this._data = options.data;
};

DataSource.prototype = {

columns: function () {
return this._columns;
},

data: function (options, callback) {

var self = this;
if (options.search) {
callback({ data: self._data, start: start, end: end, count: count, pages: pages, page: page });
} else if (options.data) {
callback({ data: options.data, start: 0, end: 0, count: 0, pages: 0, page: 0 });
} else {
callback({ data: self._data, start: 0, end: 0, count: 0, pages: 0, page: 0 });
}
}
};


var treeDataSource = new DataSource({
data: [
{ name: 'Folder 1', type: 'folder', additionalParameters: { id: 'F1' },
data: [
{ name: 'Sub Folder 1', type: 'folder', additionalParameters: { id: 'FF1' } },
{ name: 'Sub Folder 2', data: [
{name: 'sub sub folder 1', type: 'folder', additionalParameters: { id: 'FF21' }},
{name: 'sub sub item', type: 'item', additionalParameters: { id: 'FI2' }}
], type: 'folder', additionalParameters: { id: 'FF2' }},
{ name: 'Item 2 in Folder 1', type: 'item', additionalParameters: { id: 'FI2' } }
]
},
{ name: 'Folder 2', type: 'folder', additionalParameters: { id: 'F2' } },
{ name: 'Item 1', type: 'item', additionalParameters: { id: 'I1' } },
{ name: 'Item 2', type: 'item', additionalParameters: { id: 'I2' } }
],
delay: 400
});

$('#MyTree').tree({dataSource: treeDataSource});

$('#tree-selected-items').on('click', function () {
console.log("selected items: ", $('#MyTree').tree('selectedItems'));
});

$('#MyTree').on('loaded', function (evt, data) {
console.log('tree content loaded');
});

$('#MyTree').on('opened', function (evt, data) {
console.log('sub-folder opened: ', data);
});

$('#MyTree').on('closed', function (evt, data) {
console.log('sub-folder closed: ', data);
});

$('#MyTree').on('selected', function (evt, data) {
console.log('item selected: ', data);
});

});
</script>

我正在使用http://exacttarget.github.io/fuelux/#tree问题是,当我打开一个文件夹时,它仍然包含其他文件夹,如示例中所示。就像永远不会结束一样。如何避免这种情况?

谢谢。

<小时/>

编辑

我做了这个并且它起作用了..你认为它可以吗?

var cont = 0;
DataSource.prototype = {

columns: function () {
return this._columns;
},

data: function (options, callback) {

var self = this;
if (options.search) {
callback({ data: 0 , start: 0, end: 0, count: 0, pages: 0, page: 0 });
} else if (options.data) {
callback({ data: options.data, start: 0, end: 0, count: 0, pages: 0, page: 0 });
} else if (cont == 0) {
callback({ data: self._data, start: 0, end: 0, count: 0, pages: 0, page: 0 });
}
else {
callback({ data: 0, start: 0, end: 0, count: 0, pages: 0, page: 0 });
}
cont = cont+1;
}

};

使用 cont 我会在第一次(加载树时)回调数据。之后它只返回 0。

最佳答案

这是一个简单的示例:http://www.bootply.com/64521

感谢@Skelly 制定了该方法的详细信息。

关于java - Fuel UX 树递归问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18940841/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com