开发者

event listener function goes into a loop? please help

i'm facing a small issue with the fireevent. in one js file i'm firing the event like this: Ti.App.fireEvent('foo', {name:col});

in an other file i'm listening to the event.

tableimg.addEventListener('click',function(e){
        if(e.source.backgroundColor==''){CreateTableWindow(1,e.source.id);}
        else{
            changeTheDinerStatus();
            Ti.App.addEventListener('foo', function(data) 
                                    { 
                                    var ke=data.name;
                                    alert(e.source.id+'@@@'+ke);
                                    e.source.backgroundColor = ke; 
                                    });                                                 
                                    }
                                    }); 

so here is the problem, w开发者_如何学JAVAen ever i'm firing the event the function in the listener is repeating itself.....

like this

wen clicked for the first time it runs once..1@@@#FFF wen the second table is clicked it goes

1@@@#AAA 2@@@#AAA for the third time 1@@@#BBB 2@@@#BBB 3@@@#BBB

this goes on like this for all the time....


I can't see your DOM structure in front of me, but I think, the main problem is, that you add an event listener on every click. You should not do this. If you need to solve the problem this way, you should remove the existing listener

element.removeEventListener('foo',spyOnUser,false)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜