0
我有來自於服務這個對象結構:使用WHERE方法搜索對象?
var response ={"results": [
{"name":"peter" , "habits":"smoking" , "imgID":"something_unique"},
{"name":"paul" , "habits":"drinking" , "imgID":"something_unique"},
{"name":"patrick" , "habits":"gambling" , "imgID":"something_unique"}
]}
我迭代的對象,並創建它們通過點擊事件聽過的div:
for(var prop in response) {
if(response.hasOwnProperty(prop))
{
this.div.insert(new Element('div', {'className': '' })
.insert('<img id="'+imgID+'" src="/img.jpg" width=70 height=70 /> ')
);
在我的回調,我可以訪問從對象ID催生事件:
function callback (event) { console.log(event.id) ; var compare_ID=event.id }
然而,在我的回調,我需要爲一個特定的對象,這是獲得數組變量名稱點擊。因此,在概念,我希望做:
在回調,迭代response
對象,然後選擇results[i]
它是imgID
是進一步訪問== event.id return response
對象,而不僅僅是串名。
感謝,並像往常一樣,所有的幫助表示讚賞
你如何通過數據集中到一個事件的回調? – cube 2011-04-12 21:28:23
例如'results [event.target.getAttribute('data-result-number')]',或者像第二種情況那樣直接從元素'event.target.getAttribute('data-name')'中取值。這些值附加到元素節點,因此您可以通過使用'event.target'訪問元素來訪問它們。 – pepkin88 2011-04-12 21:35:18
謝謝,得到它使用你的方法工作。 – cube 2011-04-12 22:22:52