How To Create List From JSON Array?

前端 未结 5 854
渐次进展
渐次进展 2021-01-05 20:44

I have problem understanding arrays and loops, therefore this task is a bit confusing to me. Here\'s my stuff;

JSON

{
\"states\": [
         


        
5条回答
  •  佛祖请我去吃肉
    2021-01-05 20:59

    I'm checked this script and this works properly:

    var records = {
                    "states": [
                        {
                            "name": "johor",
                            "command": "view_johor"
                        },
    
                        {
                            "name": "selangor",
                            "command": "view_selangor"
                        },
    
                        {
                            "name": "melaka",
                            "command": "view_melaka"
                        },
    
                        {
                            "name": "kuala lumpur",
                            "command": "view_kl"
                        },
    
                        {
                            "name": "penang",
                            "command": "view_penang"
                        }
                    ]
                };
    
                $.each(records.states, function (key, val) {
                    $('#ul').append($('
  • ').text('name: ' + val.name + ', command: ' + val.command)); });
  • and this is html:

    
    
    
        
    
    
        

    提交回复
    热议问题