I have a treeview (using the dyna tree version) and I have extended the JS to include multiple context menus.
Originally I was using
<li id="@ID@:3.@TYPE@:3">
to hold details I may need and converted this to JSON, like so:
//Gets the ID value
var node = $.ui.dynatree.getNode(span).toString()
node = node.replace(/|/g, '\"')
node = node.replace(".", ',')
node = jQuery.parseJSON('{' + node + '}');
this was fine but unfortunately this was to be used in a razor MVC view, so @ was out. i diodnt want @@ so thought a | may be a better seperator
<li id="|ID|:3.|TYPE|:3">
But chnaging JS to
var node = $.ui.dynatree.getNode(span).toString()
node = node.replace(/|/g, '\"')
node = node.replace(".", ',')
node = jQuery.parseJSON('{' + node + '}');
gives me an error when parsing the JSON. Is there any advice on what is wrong and what characters I should be using?
The regex should have been
/\|/g, because|is a special character in regex. Anyway, this is pretty horrible way to do it, you can just have the json directly in an element:jQuery even automatically parses the json for you, when you use
.data():http://jsfiddle.net/jJQ7z/