简体   繁体   English

如何为Kendo TreeList parentID和hasChildren使用自定义字段

[英]How to use custom fields for Kendo TreeList parentID and hasChildren

I just spent 4 days working out how to do this as it is not in the documentation and I could not get any support from Telerik, even though I am a paying customer that lodged support tickets on this issue. 我只花了4天的时间来研究如何做到这一点,因为它没有包含在文档中,即使我是付费客户,但也就此问题获得了支持,我也无法从Telerik获得任何支持。 To be fair to Telerik I think this was due to one very poor support tech, they are usually pretty good. 公平地说,Telerik认为这是由于一项非常差劲的支持技术造成的,它们通常相当不错。 Telerik if you reading check out ticket numbers: 964961, 962272. Let's hope for a better response next time. 如果您正在阅读退房票,请致电Telerik:964961、962272。让我们希望下次能得到更好的答复。

In the hope that this saves someone else 4 days... here is the problem I had and how I fixed it. 希望这可以节省别人4天的时间...这是我遇到的问题以及如何解决。

I was doing a load on demand scenario with the Kendo TreeList. 我正在用Kendo TreeList进行按需负载方案。 We have our own request manager that handles all transactions with the server, so we use a JS function on the read transport for the Kendo dataSource, and use options.success(aData), to put the data returned from the server into the dataSource. 我们有自己的请求管理器来处理与服务器的所有事务,因此我们在Kendo数据源的读取传输中使用JS函数,并使用options.success(aData)将服务器返回的数据放入数据源。

We have PHP routes which call MySQL procs, and MySQL returns everything as a string, so when PHP converts the results into JSON, all non null values are sent as strings. 我们有调用MySQL proc的PHP路由,并且MySQL以字符串形式返回所有内容,因此当PHP将结果转换为JSON时,所有非null值都以字符串形式发送。 This includes the hasChildren field. 这包括hasChildren字段。

Normally this is not a problem as the Kendo dataSource will type the values correctly according to the types defined in the dataSource Schema. 通常,这不是问题,因为Kendo dataSource将根据dataSource Schema中定义的类型正确键入值。 However I found that after the data was assigned to the dataSource, all the hasChildren: "true", values would get converted to hasChildren: false and as a result no expand buttons would show on the TreeList for the load on demand items that had children. 但是我发现,在将数据分配给dataSource之后,所有hasChildren:“ true”,值都将转换为hasChildren:false,结果在TreeList上将没有展开按钮显示具有子项的按需加载项。

So I needed a way to map the hasChildren field to a typed field so the conversion from string to bool would happen. 因此,我需要一种将hasChildren字段映射到类型字段的方法,以便进行从字符串到布尔的转换。

Here what I finally got to work: 在这里,我终于开始工作了:

"OpParent": {
    "type": "number",
    "nullable": true
},
"parentId": {
    "type": "number",
    "field": "OpParent",
    "defaultValue": null
},
"OpHasChildren": {
    "type": "boolean",
    "nullable": true
},
"hasChildren": {
    "type": "boolean",
    "field": "OpHasChildren"
}

I also found that if your root level parent has a value of null, you need to set the defaultValue to null in the parentID definition. 我还发现,如果您的父级父级的值为null,则需要在parentID定义中将defaultValue设置为null。

Hopefully this will save someone the time it took to work this out. 希望这可以节省某人解决该问题的时间。

Telerik, please put this in the documentation!! Telerik,请将其放入文档中!!

Regards, 问候,

Scott 史考特

The question was the answer ;-) 问题是答案;-)

But for those that want to see the answer in the answer.... here it is: 但是对于那些想要在答案中看到答案的人。...这里是:

Here what I finally got to work: 在这里,我终于开始工作了:

"OpParent": {
    "type": "number",
    "nullable": true
},
"parentId": {
    "type": "number",
    "field": "OpParent",
    "defaultValue": null
},
"OpHasChildren": {
    "type": "boolean",
    "nullable": true
},
"hasChildren": {
    "type": "boolean",
    "field": "OpHasChildren"
}

I also found that if your root level parent has a value of null, you need to set the defaultValue to null in the parentID definition. 我还发现,如果您的父级父级的值为null,则需要在parentID定义中将defaultValue设置为null。

Hopefully this will save someone the time it took to work this out. 希望这可以节省某人解决该问题的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM