Do you mean : hosw to find it's parent ?
2009/12/10 maalek <maaa...@gmail.com> > Hello > > I have problem with my Objects. My object have many props and method, > one of this is td (screen reprezentation of the object). I observe > click event to obj.td where I do many things on this object and change > td (screen reprezentation). My question : how find object where is > attach clicked td ? > > Now I setAttribute to td something like obj_id, when td is clicked > first I read this attribute from td, find proper object by this id, do > what to do and finnaly change state of obj.td. This works fine but > when I have very many obj (like thousand), find object takes many time > (find object is longer then do what to do). > > > Here is simple example : > > // example START > > Event.observe(window, 'load', function() { > onLoad(); > }); > > var objTrs = []; > var msg = null; > > function onLoad(){ > > msg = document.createElement("div"); > msg.innerHTML = "Click on cell"; > $(document.body).appendChild(msg); > > var table = document.createElement("table"); > var tableBody = document.createElement("tbody"); > table.appendChild(tableBody); > $(document.body).appendChild(table); > table.border="1" > > for(var i = 0; i < 10; i++){ > var myTr = {}; > myTr.counter = 0; > myTr.tr = document.createElement("tr"); > myTr.objTds = []; > objTrs.push(myTr); > for (var j = 0; j < 10; j++){ > var myTd = {}; > myTd.counter = 0; > myTd.td = document.createElement("td"); > myTd.td.setAttribute('tr_id',i); > myTd.td.setAttribute('td_id',j); > myTd.td.innerHTML = myTr.counter + "_" + myTd.counter; > myTr.objTds.push(myTd); > myTr.tr.appendChild(myTd.td); > > Event.observe(myTd.td, 'click', function() { > // find tr object in array > var tr_id = this.getAttribute("tr_id"); > var myTr = objTrs[tr_id]; > myTr.counter++; > // find proper td in myTr > var td_id = this.getAttribute("td_id"); > var myTd = myTr.objTds[td_id]; > myTd.counter++; > var msgTxt = "you click " + myTr.counter + " times on this TR > and " + myTd.counter + " on this TD"; > myTd.td.innerHTML = myTr.counter + "_" + myTd.counter; > msg.innerHTML = msgTxt; > }); > > } > tableBody.appendChild(myTr.tr); > } > > } > > // example STOP > > Best regards > maalek > > -- > > You received this message because you are subscribed to the Google Groups > "Prototype & script.aculo.us" group. > To post to this group, send email to > prototype-scriptacul...@googlegroups.com. > To unsubscribe from this group, send email to > prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculous%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/prototype-scriptaculous?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.