有沒有辦法,因爲我迭代通過JSON文件關聯某些數組元素與點擊處理程序的列表?關聯JSON數組元素與事件處理程序
什麼我是這樣的:
$.ajax(
{
url: 'json/data.json',
dataType : 'json',
type: 'get',
cache: false,
success: function(fullJSONData)
{
$(fullJSONData.events).each(function(index, oneJSONLine)
{
$('#eventList').append(newEvent(index, oneJSONLine))
$("#eventItem" + index).on("click", showEvent (fullJSONData.events[index]));
});
},
error: function (e)
{
console.log("error " + e.message);
}
});
這不是工作,因爲所有的showEvent事件處理程序()指向的最後一個值,這是在指數。我能以某種方式解決這個問題嗎?
謝謝
感謝那@charlietfl,很好的學習差異 – Scone