【发布时间】:2015-09-19 18:33:25
【问题描述】:
我正在处理一个网上商店模板,我需要根据商店中的每一个产品,在单击给定产品时打开的模式中显示正确的 JSON 数据。我还使用车把进行模板化,并具有以下代码结构:
.html(打开模式的按钮)
<button type="button" class="quickview">Open Modal</button>
.html(模态)
<div id="quickview-modal">
modal content that should iterate over the JSON and display one item at a time depending on the ID
</div>
.json
{
"productID" : "1",
"name" : "productOne"
},
{
"productID" : "2",
"name" : "productTwo"
}
.js
$( ".quickview" ).click(function( event ) {
$('#quickview-modal').modal('show');
event.stopPropagation();
// Do something
});
有什么想法可以解决这个问题吗?谢谢!
【问题讨论】:
-
您要显示
json中的所有#quickview-modal数据吗? -
按
productID对其进行排序,然后遍历排序后的数组。 stackoverflow.com/questions/11099610/…
标签: javascript jquery html json