关于Kendo的API参考(证明:Kendo UI API Reference - Schema.Model.Children),子节点可以在下一种方法中声明(参见嵌套'schema'作为'第二级的定义选项'):
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使用类似的定义,并以这种方式获取子节点:
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"
}
没关系。我可以这样看待孩子们。但默认情况下,'hasChildren'的属性为'true',我为子节点添加方案,如API参考:
children: { // <- instead of "PhoneCalls" - next 'schema'
schema: {
data: "PhoneCalls",
model: { hasChildren: false }
}
}
,并且非常失去孩子。
任何人都可以帮助正确定义带有方案的子属性吗?
答案 0 :(得分:0)
您只需设置树视图的数据,就可以在不定义架构的情况下完成。
data = [{id:&#39; 1&#39;,text:&#39; Music&#39;,items:[{id:&#39; 1.1&#39;,text:&#39 ;国家&#39;,项目:[]},{id:&#39; 1.2&#39;,文字:&#39; Jazz&#39;,项目:[]}]}];
$(&#34;#树形目录&#34)的数据。(&#34; kendoTreeView&#34)dataSource.data(数据);
答案 1 :(得分:0)
解决方案: 1.忘记&#39;架构&#39;支撑儿童&#39; - 转回&#34; PhoneCalls&#34;字符串值。 2.添加&#39; hasChildren&#39; “电话呼叫”中的财产。对象(来自&#34; PhoneCalls&#34;设置)并将值设置为&#39; false&#39;。
如果要添加新级别的树视图: 1.设置&#39; hasChildren&#39; &#34; PhoneCall&#34;的财产对象&#39; true&#39; 2.将从属集添加为&#34; PhoneCall&#34;的属性。对象 3.添加孩子&#39;属于&#34; PhoneCall&#34;可以是字符串值的对象 - 来自p的set属性的名称。 2