0

我对 Javascript 很陌生,所以我不确定我是否做对了。首先,我使用 JSON 创建一个数组对象“providerlisting”。接下来我正在创建一个 for 循环,它应该循环遍历 html,直到 JSON 数组中没有更多列表。我不确定我的语法是否正确。我对问这些问题也很陌生,所以如果我做错了,我很抱歉。

for (var i=0;i<providerlisting.length;i++)
{ document.write('<div class="entry panel row">
                    <div class="large-4 columns first">
                        <div class="name">'providerlisting.nametitle[i]'</div>
                        <div class="specialty">'providerlisting.caretype[i]'</div>
                        <div class="peferred">'providerlisting.preferredprovider[i]'</div>
                    </div>
                    <div class="large-3 columns second">
                        <div class="address">'providerlisting.address1[i]'<br />
                        'providerlisting.address2[i]'<br />
                        'providerlisting.citystatezip[i]'
                        </div>
                    </div>
                    <div class="large-3 columns third">
                        <img src="'providerlisting.coverage[i]'" alt="example">
                    </div>
                    <div class="large-2 columns fourth">
                        <div class="status">'providerlisting.status[i]'</div>
                        <a data-dropdown="actionsMenu2" class="actions button small secondary round dropdown" href="#">Actions</a><br>
                        <ul id="actionsMenu2" data-dropdown-content="" class="f-dropdown">
                            <li><a href="'providerlisting.psn[i]'">Generate PSN</a></li>
                            <li><a href="'providerlisting.dcontact[i]'">Download Contact</a></li>
                            <li><a href="'providerlisting.save[i]'">Save to Provider List</a></li>
                            <li><a href="'providerlisting.rating[i]'">View Healthgrades Rating</a></li>
                        </ul>
                    </div>
                </div>
     ');
4

1 回答 1

1

我不能确切地说,因为你还没有发布你的 JSON,但应该这样做:

for(var i = 0; i < providerlisting.length; i++) {
    document.write('<div class="entry panel row">
                    <div class="large-4 columns first">
                        <div class="name">'+ providerlisting[i].nametitle +'</div>
                        <div class="specialty">'+ providerlisting[i].caretype +'</div>
                        <div class="peferred">'+ providerlisting[i].preferredprovider +'</div>
                    </div>
                    <div class="large-3 columns second">
                        <div class="address">'+ providerlisting[i].address1 +'<br />
                        '+ providerlisting[i].address2 +'<br />
                        '+ providerlisting[i].citystatezip +'
                        </div>
                    </div>
                    <div class="large-3 columns third">
                        <img src="'+ providerlisting[i].coverage +'" alt="example">
                    </div>
                    <div class="large-2 columns fourth">
                        <div class="status">'+ providerlisting[i].status +'</div>
                        <a data-dropdown="actionsMenu2" class="actions button small secondary round dropdown" href="#">Actions</a><br>
                        <ul id="actionsMenu2" data-dropdown-content="" class="f-dropdown">
                            <li><a href="'+ providerlisting[i].psn +'">Generate PSN</a></li>
                            <li><a href="'+ providerlisting[i].dcontact +'">Download Contact</a></li>
                            <li><a href="'+ providerlisting[i].save +'">Save to Provider List</a></li>
                            <li><a href="'+ providerlisting[i].rating +'">View Healthgrades Rating</a></li>
                        </ul>
                    </div>
                </div>');
}

我把每一个都providerlisting.prop[i]改成了providerlisting[i].prop. 您还以错误的方式串在一起:

var str = 'some words'someVariable'more words'不会工作。

var str = 'some words'+ someVariable +'more words'将要。

于 2013-08-27T18:53:16.003 回答