I'm creating an App with a filesystem. The filesystem contains folders wichs may contain folder or files. Before requesting the transport.read() we don't know if a folder contains subitems. We assume that a folder will contain subitems, so we set "hasChildren" property to true.
How we set "hasChildren" to false once the request returns no subitems, to make the expanding tree dissappear ?
fileSystem: {
items: new kendo.data.HierarchicalDataSource({
transport: {
read: function(options) {
var url = (options.data && options.data.src) ? options.data.src : null;
var request = PncServices.getFilesytem(url, {});
request.done(function(data, textStatus, jqXHR) {
var items = [];
$.each(data, function(key, value) {
var uri = URI(value);
var parts = uri.toString().split("/");
var index = (parts[parts.length-1] === "") ? parts.length-2 : parts.length-1;
var isFolder = (index === parts.length-1);
var label = parts[index];
var item = {
src: value,
label: label,
hasChildren: !isFolder
};
if(items.length <= 0) {
//TODO: Set hasChildren to false
//fileSystem.items.get(url).set("hasChildren", false);
}
items.push(item);
});
options.success(items);
});
request.fail(function(jqXHR, textStatus, errorThrown) {
options.error(errorThrown);
});
},
},
schema: {
model: {
id: "src",
hasChildren: "hasChildren"
}
}
})
How we set "hasChildren" to false once the request returns no subitems, to make the expanding tree dissappear ?
fileSystem: {
items: new kendo.data.HierarchicalDataSource({
transport: {
read: function(options) {
var url = (options.data && options.data.src) ? options.data.src : null;
var request = PncServices.getFilesytem(url, {});
request.done(function(data, textStatus, jqXHR) {
var items = [];
$.each(data, function(key, value) {
var uri = URI(value);
var parts = uri.toString().split("/");
var index = (parts[parts.length-1] === "") ? parts.length-2 : parts.length-1;
var isFolder = (index === parts.length-1);
var label = parts[index];
var item = {
src: value,
label: label,
hasChildren: !isFolder
};
if(items.length <= 0) {
//TODO: Set hasChildren to false
//fileSystem.items.get(url).set("hasChildren", false);
}
items.push(item);
});
options.success(items);
});
request.fail(function(jqXHR, textStatus, errorThrown) {
options.error(errorThrown);
});
},
},
schema: {
model: {
id: "src",
hasChildren: "hasChildren"
}
}
})