PDA

View Full Version : how to use correctly insertBefore::DomHelper with the UM??



luke83
5 Nov 2006, 6:30 PM
i'm using this code:


var rListMsgs = new function(){
this.render = function(el, response){
var dh = YAHOO.ext.DomHelper;
var obj = response.responseText;
obj=obj.split("\n");
for (v in obj)
dh.insertBefore('item0', {tag: 'li', html: obj[v]});
}
}();

var dh = YAHOO.ext.DomHelper;
dh.append('container',{tag:'div',id:'room', html:'prova'});
dh.append('room', {tag: 'ul', children: [
{tag: 'li', id: 'item0', html: 'List Item 0'}
]
});
room = getEl("room").getUpdateManager();;
room.setRenderer(rListMsgs);
room.update('msg.php');
room.startAutoRefresh(4,'msg.php');


to try to add before the element item0 inside the list in the room div other elements to the list

[dom tree]

-div (room)
--ul
<-- here i wanna be :D
---li (item0)
[/dom tree]

the code don't work.. :cry:

also if i use .append method it only replace the whole room content and not - as i would - only add li elements to the ul inside room div

what is wrong?

ps:

msg.php output is:


item1
item2
....
....
...

jack.slocum
5 Nov 2006, 7:57 PM
You will want to get the update manager for the UL, not the "room".

...
var ul = dh.append('room', {tag: 'ul', children: [
{tag: 'li', id: 'item0', html: 'List Item 0'}]}, true);

var um = ul.getUpdateManager();;
um.setRenderer(rListMsgs);
um.update('msg.php');
um.startAutoRefresh(4,'msg.php');

We can get the UL by assigning a var to the return value. We pass true as the third parameter to say we want an Element back (0.33 beta 1+). The rest is the same but changed to the ul's UpdateManager.