Hi All!
This is my 1st post, i´m evaluating this component's and i have a question that may be easy.
Trying to integrate with SharePoint a Tree object, but having problems getting the data for binding. This is my main code thar return a Json object
Object Array in Json Format "deps"
function getDepartamentos() {
var context = new SP.ClientContext("/");
var list = context.get_web().get_lists().getByTitle("Departamentos");
var viewXml = "<View><RowLimit>1200</RowLimit></View>";
var query = new SP.CamlQuery();
query.set_viewXml(viewXml);
var items = list.getItems(query);
context.load(items, "Include(DepId,DepParentId,Title)");
function onLoaded() {
var deps = [];
var itemsCount = items.get_count();
for (var i = 0; i < itemsCount; i++) {
var item = items.itemAt(i);
var dep = JSON.stringify(item.get_fieldValues());
deps.push(dep);
}
return deps;
}
context.add_requestSucceeded(onLoaded);
function onFailure() {
}
context.add_requestFailed(onFailure);
context.executeQueryAsync();
$("#tt").tree({
});
}
I have another code that get's the Id and Parent
unction convertToTree(rows) {
function exists(rows, parentId) {
for (var i = 0; i < rows.length; i++) {
if (rows[i].id == parentId) return true;
}
return false;
}
var nodes = [];
// get the top level nodes
var row;
var i;
for (i = 0; i < rows.length; i++) {
row = rows[i];
if (!exists(rows, row.parentId)) {
nodes.push({
id: row.id,
text: row.name
});
}
}
var toDo = [];
for (i = 0; i < nodes.length; i++) {
toDo.push(nodes[i]);
}
while (toDo.length) {
var node = toDo.shift(); // the parent node
// get the children nodes
for (i = 0; i < rows.length; i++) {
row = rows[i];
if (row.parentId == node.id) {
var child = { id: row.id, text: row.name };
if (node.children) {
node.children.push(child);
} else {
node.children = [child];
}
toDo.push(child);
}
}
}
return nodes;
}
How can i load this in? without a URL
$("#tt").tree({
});
Thank You
Joao