So here is the deal: I have a JSON object stored in my web application in localStorage. This JSON is saved as a string with JSON.stringifyinside one of my functions when the page loads:
localStorage.setItem("MyData", JSON.stringify(data));
data is saved as follows:
[{"NAMEVAR":"Some Data 1","CODE":"1"},{"NAMEVAR":"Some Data 2","CODE":"2"}]
data is the result of a query. The data is successfully saved on the main page, so I can use it later. After that I need to load the form on another page, using what I got from the data.
I have this select tag on the page:
<select id="mySelectID" name="select" class="main-form">
<option value="">None Selected</option>
</select>
What I want to do is simple: I use json2html to add elements to this select tag from the data, and the parameter value has CODE from the data. So, I expected this to happen:
<select id="mySelectID" name="select" class="main-form">
<option value="1">Some Data 1</option>
<option value="2">Some Data 2</option>
</select>
by doing the following:
var jsonData = $.parseJSON(window.localStorage.getItem("data"));
var transform = {tag:'option', id:'.CODE',html:'{$NAMEVAR}'};
document.getElementById('mySelectID').innerHtml = json2html.transform(jsonData,transform);
, , . , , JSON HTML. , json2html , - -, - , JavaScript.
!