问题描述
我的项目中有类似可拖动树的要求.我已经成功将mssql结果集转换为json.
I've a requirement like dragable tree in my project.I've successfully converted mssql resultset to json.
但是最终用户再次拖放并完全更改了树形结构.现在,我从客户端获得了以下json.
But the end user is again dragging and dropping and totally changed the tree structure.Now I have the below json from the client.
[
{
"id": 1,
"title": "1. dragon-breath",
"items": [
{
"id": 10,
"title": "1. dragon-breath.1",
"items": [
{
"id": 100,
"title": "1. dragon-breath.1.2",
"items": [
{
"id": 1000,
"title": "1. dragon-breath.1.2.3",
"items": [],
"pos": 3
}
],
"pos": 2
},
{
"id": 101,
"title": "1. dragon-breath.1.2",
"items": [],
"pos": 2
}
],
"pos": 1
}
],
"pos": 1
},
{
"id": 102,
"title": "1. dragon-breath.1.2",
"items": [
{
"id": 1020,
"title": "1. dragon-breath.1.2.1",
"items": [],
"pos": 1
}
],
"pos": 2
},
{
"id": 1021,
"title": "1. dragon-breath.1.2.1",
"items": [],
"pos": 1
}
]
上面的json"pos"属性用于MSSQL Hierarchyid值.
From the above json "pos" property is for MSSQL Hierarchyid value.
当此json从客户端发回时,我正在尝试重新生成每个元素的层次结构ID.
I am trying to regenerate the hierarchy id of each element, when this json posted back from the client.
我正在请求你们的人帮助我.(花2天没有运气)
I am requesting you people to help me. (spend 2 days no luck)
推荐答案
在您发布到另一个SO问题的链接,然后是评论的链接之后,我看到您正在使用MSSQL hierarchyid
数据类型(提示:如果您对问题有所了解,可能会有所帮助;)
Following the link you posted to the other SO question, and then a link from a comment, I see you are using the MSSQL hierarchyid
data type (hint: it might have helped if you been a bit clearer about that in your question ;)
从联机帮助中,我看到有一个解析函数,需要一个字符串.
From the online help I see there is a Parse function, which takes a string.
因此,您需要遍历JSON树结构,例如以/1/1/3/
的形式为每个元素构建字符串,并将这些字符串以及关联的节点传递回数据库 id
.
So you need to traverse your JSON tree structure, building strings for each element in the form /1/1/3/
for example, and pass those back to your database along with the associated node id
.
这篇关于如何为树对象的每个元素生成MSSQL层次结构ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!