Insert into HTML select tag options from a JSON

前端 未结 6 1785
甜味超标
甜味超标 2021-02-09 14:18

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:12

    I think there are a couple of errors in your code. Try this instead:

    // it's class, not id, and no fullstop required.
    // The $ sign was in the wrong place.
    var transform = {tag:'option', class:'$(CODE)', html:'${NAMEVAR}'};
    
    // it's innerHTML not innerHtml
    document.getElementById('mySelectID').innerHTML = json2html.transform(jsonData, transform);
    

提交回复
热议问题