在视图中准备一个json对象来传递控制器
我有一棵具有 ul li HTML 结构的树。
每个 li 中都有一个包含树的节点名称的跨度。
我必须在读取树后创建一个 json 对象,它应该看起来像这样的东西,
this.orgStructureId = null;
this.name = null;
this.nodeList = null;
this.parent = null;
this.list = null;
我不确定它将是结构,但有一些类似的东西。那么我怎样才能制作这个对象,你需要更多的输入来制作json 对象。
i have a tree that has a ul li HTML structure .
In every li there is a span that contains the node name of the tree.
I have to make a json object after reading the tree it should look like some thing in this manner
this.orgStructureId = null;
this.name = null;
this.nodeList = null;
this.parent = null;
this.list = null;
i am not sure that it will be the structure but some thing similar.so how can i make this object do you need any more inputs for making the json object.
https://i.sstatic.net/9itqx.jpg
Tree sample snap shot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
然后你只需要序列化它
Then you just need to serialize it
树是在服务器上生成的
如果您的树是在服务器端生成的,您也可以将其 JSON 字符串添加到您的 HTML 中并使用预先准备好的 JSON 数据,而不是在客户端生成......
然后只需调用
即可将获取要发送到服务器的 JSON 数据。但是还有另一个障碍......将数据传递给控制器操作。
我建议您阅读 这篇关于发送 JSON 数据的博客文章,这将使您的生活更加轻松...
树在客户端生成
如果您的树是由用户在客户端生成/编辑的,您将别无选择,只能:
我可能会选择第二个,因为无论如何您都已经在操作数据了。那么为什么不生成 HTML 节点并填充变量呢?
Tree is generated on the server
If your tree is generated on the server side, you could as well add its JSON string to your HTML and use that preprepared JSON data instead of generating in on the client side...
Then just call
and you'll get your JSON data to send to the server. But there will be another obstacle... passing that data to controller action.
I suggest you read this blog post about sending JSON data, that will make your life even easier...
Tree is generated on the client
In case your tree is generated/edited on the client by users you will have no other option but either:
I'd probably go with the second one, because you'll be manipulating data already anyway. So why not generate HTML nodes and populate variables as well.