Kendo UI 层次结构 children 模式
Kendo UI hierarchy children schema
关于 API 对 Kendo 的引用(证明:Kendo UI API Reference - Schema.Model.Children),children 节点可以在下一个方法中声明(参见嵌套 'schema'作为 'define options for second level'):
var datasource = new kendo.data.HierarchicalDataSource({
data: [
{
categoryName: "SciFi",
movies: [
{ title: "Star Wars: A New Hope", year: 1977, cast: [
{ actor: "Mark Hamill", character: "Luke Skywalker" },
{ actor: "Harrison Ford", character: "Han Solo" },
{ actor: "Carrie Fisher", character: "Princess Leia Organa" }
] },
{ title: "Star Wars: The Empire Strikes Back", year: 1980, cast: [
{ actor: "Mark Hamill", character: "Luke Skywalker" },
{ actor: "Harrison Ford", character: "Han Solo" },
{ actor: "Carrie Fisher", character: "Princess Leia Organa" },
{ actor: "Billy Dee Williams", character: "Lando Calrissian" }
] }
]
}
],
schema: {
model: {
children: { // define options for second level
schema: {
data: "movies",
model: {
children: "cast" // third level is defined by the field "cast"
}
}
}
}
}
});
我对 HierarchicalDataSource 使用类似的定义并以这种方式获得 children 个节点:
schema: {
model: {
id: "urb_fltr",
hasChildren: true,
children: "PhoneCalls" // <- here is definition for children that are - data from field of output (next in parse)
},
parse: function (data) {
var outRes = [];
var dataRes = [];
var tmpLoop = 0;
var bordNum = 251170009;
if (data.d.results != null && data.d.results.length > 0)
for (var step = 0; step < data.d.results.length; step++) {
if (data.d.results[step] == null) continue;
var stepData = data.d.results[step];
var stepValue = (stepData.urb_subject != null) ? stepData.urb_subject.Value : 0;
var arrValue = (stepValue > bordNum) ? stepValue - bordNum : 0;
if (outRes[arrValue] == null || typeof (outRes[arrValue]) == 'undefined') {
outRes[arrValue] = {};
outRes[arrValue].urb_total = 1;
outRes[arrValue].urb_clnts = 0;
outRes[arrValue].OwnerId = stepData.OwnerId;
outRes[arrValue].urb_subjectValue = stepValue;
outRes[arrValue].PhoneCalls = []; // <- children
}
else
outRes[arrValue].urb_total += 1;
// fill children field
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1] = {};
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].CallId = stepData.ActivityId;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].urb_name = stepData.urb_name;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].CreatedOn = stepData.CreatedOn;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].PhoneNumber = stepData.PhoneNumber;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].ScheduledEnd = stepData.ScheduledEnd;
if (stepData.RegardingObjectId != null && stepData.RegardingObjectId.Id != null && stepData.RegardingObjectId.LogicalName == "lead") {
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].RegardingObjectId = stepData.RegardingObjectId;
outRes[arrValue].urb_clnts += 1;
}
}
for (var loop = 0; loop < outRes.length; loop++)
if (typeof (outRes[loop]) != 'undefined') {
outRes[loop].urb_subjectName = outRes[loop].urb_subjectName + " ( " + outRes[loop].urb_total + " - " + outRes[loop].urb_clnts + " )";
dataRes[tmpLoop] = outRes[loop];
tmpLoop++;
}
return dataRes; //data.d.results;
},
type: "json"
}
没关系。我可以这样看children。但默认情况下,'hasChildren' 的 属性 是 'true' 并且我为 children 节点添加方案,如 API 参考:
children: { // <- instead of "PhoneCalls" - next 'schema'
schema: {
data: "PhoneCalls",
model: { hasChildren: false }
}
}
,相当输children.
谁能帮助正确定义 children 属性 方案?
只设置treeview的数据即可,无需定义schema即可。
data = [{id: '1', text: 'Music', items: [{id: '1.1', text: 'Country', items: []}, {id: '1.2',文本:'Jazz',项目:[]}]}];
$("#treeView").data("kendoTreeView").dataSource.data(数据);
解决方法:
1. 忘记 'children' 中的 'schema' 大括号 - 返回 "PhoneCalls" 字符串值。
2、在'PhoneCall'对象中添加'hasChildren'属性(来自"PhoneCalls"集合),并在'false'.
中设置值
如果要添加新级别的树视图:
1.在'true'中设置'hasChildren'属性个"PhoneCall"个对象
2. 添加从属集作为"PhoneCall"个对象的属性
3. 在 "PhoneCall" 对象中添加 'children' 属性 这将是一个字符串值 - 来自 p 的集合属性的名称。 2
关于 API 对 Kendo 的引用(证明:Kendo UI API Reference - Schema.Model.Children),children 节点可以在下一个方法中声明(参见嵌套 'schema'作为 'define options for second level'):
var datasource = new kendo.data.HierarchicalDataSource({
data: [
{
categoryName: "SciFi",
movies: [
{ title: "Star Wars: A New Hope", year: 1977, cast: [
{ actor: "Mark Hamill", character: "Luke Skywalker" },
{ actor: "Harrison Ford", character: "Han Solo" },
{ actor: "Carrie Fisher", character: "Princess Leia Organa" }
] },
{ title: "Star Wars: The Empire Strikes Back", year: 1980, cast: [
{ actor: "Mark Hamill", character: "Luke Skywalker" },
{ actor: "Harrison Ford", character: "Han Solo" },
{ actor: "Carrie Fisher", character: "Princess Leia Organa" },
{ actor: "Billy Dee Williams", character: "Lando Calrissian" }
] }
]
}
],
schema: {
model: {
children: { // define options for second level
schema: {
data: "movies",
model: {
children: "cast" // third level is defined by the field "cast"
}
}
}
}
}
});
我对 HierarchicalDataSource 使用类似的定义并以这种方式获得 children 个节点:
schema: {
model: {
id: "urb_fltr",
hasChildren: true,
children: "PhoneCalls" // <- here is definition for children that are - data from field of output (next in parse)
},
parse: function (data) {
var outRes = [];
var dataRes = [];
var tmpLoop = 0;
var bordNum = 251170009;
if (data.d.results != null && data.d.results.length > 0)
for (var step = 0; step < data.d.results.length; step++) {
if (data.d.results[step] == null) continue;
var stepData = data.d.results[step];
var stepValue = (stepData.urb_subject != null) ? stepData.urb_subject.Value : 0;
var arrValue = (stepValue > bordNum) ? stepValue - bordNum : 0;
if (outRes[arrValue] == null || typeof (outRes[arrValue]) == 'undefined') {
outRes[arrValue] = {};
outRes[arrValue].urb_total = 1;
outRes[arrValue].urb_clnts = 0;
outRes[arrValue].OwnerId = stepData.OwnerId;
outRes[arrValue].urb_subjectValue = stepValue;
outRes[arrValue].PhoneCalls = []; // <- children
}
else
outRes[arrValue].urb_total += 1;
// fill children field
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1] = {};
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].CallId = stepData.ActivityId;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].urb_name = stepData.urb_name;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].CreatedOn = stepData.CreatedOn;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].PhoneNumber = stepData.PhoneNumber;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].ScheduledEnd = stepData.ScheduledEnd;
if (stepData.RegardingObjectId != null && stepData.RegardingObjectId.Id != null && stepData.RegardingObjectId.LogicalName == "lead") {
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].RegardingObjectId = stepData.RegardingObjectId;
outRes[arrValue].urb_clnts += 1;
}
}
for (var loop = 0; loop < outRes.length; loop++)
if (typeof (outRes[loop]) != 'undefined') {
outRes[loop].urb_subjectName = outRes[loop].urb_subjectName + " ( " + outRes[loop].urb_total + " - " + outRes[loop].urb_clnts + " )";
dataRes[tmpLoop] = outRes[loop];
tmpLoop++;
}
return dataRes; //data.d.results;
},
type: "json"
}
没关系。我可以这样看children。但默认情况下,'hasChildren' 的 属性 是 'true' 并且我为 children 节点添加方案,如 API 参考:
children: { // <- instead of "PhoneCalls" - next 'schema'
schema: {
data: "PhoneCalls",
model: { hasChildren: false }
}
}
,相当输children.
谁能帮助正确定义 children 属性 方案?
只设置treeview的数据即可,无需定义schema即可。
data = [{id: '1', text: 'Music', items: [{id: '1.1', text: 'Country', items: []}, {id: '1.2',文本:'Jazz',项目:[]}]}];
$("#treeView").data("kendoTreeView").dataSource.data(数据);
解决方法: 1. 忘记 'children' 中的 'schema' 大括号 - 返回 "PhoneCalls" 字符串值。 2、在'PhoneCall'对象中添加'hasChildren'属性(来自"PhoneCalls"集合),并在'false'.
中设置值如果要添加新级别的树视图: 1.在'true'中设置'hasChildren'属性个"PhoneCall"个对象 2. 添加从属集作为"PhoneCall"个对象的属性 3. 在 "PhoneCall" 对象中添加 'children' 属性 这将是一个字符串值 - 来自 p 的集合属性的名称。 2