MyClass = Class.create( { ... displayFeeds: function(items){ var ul = $('itemsList'); for (var i = 0; i < items.length; i++) { var li = new Element('li'); var text = new Element('a', {'href': '#'}).update(items[i].title); li.insert(text); ul.insert(li); text.observe('click', this.printDynamic.bind(this,items[i].link)); } }, localVar : "my class local variable", printDynamic: function(link){ this.localVar = link; } });
We have JQuery full equivalent below
MyClass = Class.create( { ... displayFeeds: function(items){ var ul = $('#itemsList'); for (var i = 0; i < items.length; i++) { var li = $("<li><a href='#DetailsScreen'>"+items[i].title+"</a></li>"); li.bind('click',{url:items[i].link}, $.proxy(this.printDynamic, this)); li.appendTo( ul ); } }, localVar : "my class local variable", printDynamic: function(event){ this.localVar = event.data.url; } });
No comments:
Post a Comment