Insert into HTML select tag options from a JSON

前端 未结 6 997
南方客
南方客 2021-02-09 14:32

So, here\'s the deal: I have a JSON object saved in my web App at localStorage. This JSON is being saved as a string, with JSON.stringify, inside one of my function

6条回答
  •  难免孤独
    2021-02-09 15:03

    most immediately you need to change this:

    var jsonData = $.parseJSON(window.localStorage.getItem("data"));
    var transform = {tag:'option', id:'.CODE',html:'{$NAMEVAR}'};
    

    To this:

    var jsonData = $.parseJSON(window.localStorage.getItem("MyData"));
    var transform = {tag:'option', id:'{$CODE}',html:'{$NAMEVAR}'};
    

    That's just a key to get to the data, so make sure you use the same key.

    There may be some difficulty in rendering:

    value="1"
    

    As you are depending id="{$CODE}" to translate to that, which it will not do automatically.

    Good luck!

提交回复
热议问题