我從數據listCards中讀取並使用jQuery顯示循環中的卡片列表。使用jquery讀取和顯示數據
但我只在控制檯中獲得一個空數組。
請告訴我我做錯了什麼?
<script>
var listCards = [{
"cardTitle": "Sample Ttile",
"cardDate": "05 April 2017",
"cardLinkURL": "#",
"cardLinkDTM": "data-tracker-id=\"cards_1_1\" data-tracker-type=\"button\" data-tracker_ei=\"cards_1_1\" "
},
{
"cardTitle": "Sample Ttile 2",
"cardDate": "05 April 2017",
"cardLinkURL": "#",
"cardLinkDTM": "data-tracker-id=\"cards_1_1\" data-tracker-type=\"button\" data-tracker_ei=\"cards_1_1\" "
}]
</script>
所以我到目前爲止已經做的是
$(".list-view").on('click', staticListCards);
\t \t \t \t \t function staticListCards(){
\t \t \t \t \t \t console.log("Called");
\t \t \t \t \t \t $.each(listCards, function (index, value) {
\t \t \t \t \t \t \t console.log(value);
\t \t \t \t \t \t \t }); \t \t
\t \t \t \t \t }
你設置'listCards = staticListCards',然後調用'listCards.forEach(...'。因此,你打電話'的forEach()'上'function', –
刪除此'var listCards = staticListCards; console.log(listCards);'並檢查 –