使用JavaScript阅读JSON

时间:2017-05-17 20:04:16

标签: javascript json

我想用我的HTML中的JSON替换具有相同JSON数据的URL端点(http://localhost:3000/staff)。知道如何做到这一点吗?不使用jQuery优先。

        <div class="panel" data-title="Staff" id="staff_panel">
            <li class="divider">ACADEMIC</li>
            <ul class="list">
                <div id='stringifiedJSON_academic_staff'></div>
            </ul>
        </div>

<script type="text/javascript">
var people;

    people = [
      { first_name: 'Don Molloy', category: 'academic' },
      { first_name: 'Pat Quill', category: 'academic' },
      { first_name: 'Regina Mundi', category: 'administrative' },
      { first_name: 'Pat Flynn', category: 'technical' }
    ];

for (var i = 0; i < people.length; i++) {
    console.log(i, people[i].first_name);

    if (people[i].category == 'academic') {
        console.log(people[i].first_name);
        var stringifiedJSON_academic_staff = '<li><a href="https://www.w3schools.com/html/">'+JSON.stringify(people[i].first_name+'</a></li>');
        document.getElementById('stringifiedJSON_academic_staff').innerHTML += stringifiedJSON_academic_staff;
    }
}

0 个答案:

没有答案