On 10/1/07, Lee Hinde <[EMAIL PROTECTED]> wrote: > On 10/1/07, Lee Hinde <[EMAIL PROTECTED]> wrote: > > Hi; > > > > I have questions about selectors and .each. > > > > Given this result: > > > > <queryResult parent="2" queryid="C10012007113409LEQY" > > recordsinselection="2" size="2" sortfield="" tableid="2" > > tablename="Person"> > > <row locked="False" recordid="[2][1]" selectionid="1"> > > <field fieldrecordid="1" id="[2][1]">3</field> > > <field fieldrecordid="1" id="[2][2]">1</field> > > <field fieldrecordid="1" id="[2][3]">Molly</field> > > <field fieldrecordid="1" id="[2][4]">Hinde</field> > > <field fieldrecordid="1" id="[2][5]">Adult Supervision</field> > > </row> > > <row locked="False" recordid="[2][0]" selectionid="2"> > > <field fieldrecordid="0" id="[2][1]">2</field> > > <field fieldrecordid="0" id="[2][2]">1</field> > > <field fieldrecordid="0" id="[2][3]">Lee</field> > > <field fieldrecordid="0" id="[2][4]">Hinde</field> > > <field fieldrecordid="0" id="[2][5]">Night Custodial Staff</field> > > </row> > > </queryResult> > > > > what's the best way to iterate through to build table rows from the data? > > > > I started with: > > > > $j("row > field",dataXML).each(function(i){ > > var fID = $j(this).attr("id"); > > > > if(fID=="[2][1]") {//we don't need this field, but we > > only want to initialze once per record. > > var hID = $j(this).parent().attr("recordid"); > > var newRow = > > $j("<tr>").attr("class","selectableRow").attr("id","r"+i); > > };//end init > > > > if(fID=="[2][3]"){ > > var pname = $j(this).text(); > > }; > > if(fID=="[2][4]"){ > > pname = pname+" "+$j(this).text(); > > newRow.append("<td>"+fname+"</td>"); > > }; > > if(fID=="[2][5]"){ > > var aRow = > > newRow.append("<td>"+$j(this).text()+"</td>"); > > $j("#peopleList").append(aRow); > > postDebug(pname); > > > > }; > > > > }) > > > > (figuring I'd optimize after it was working) and I was surprised that > > "i" didn't always start at 0. Also, it seems wrong, I really want to > > process rows, not fields. So, my question is, how do I iterate through > > the rows and pull out the fields that I want to display. > > > > Starting with: > > > > $j("row",dataXML).each( > > function(i){ > > var fname = > > $j(this).$j("field").attr("id","[2][3]").text(); > > > > > > }); > > which doesn't work. Then I tried: > > > > var fname = this.$j("field").attr("id","[2][3]").text(); > > > > and > > > > var fname =$j(this> "field").attr("id","[2][3]").text(); > > > > neither of which worked. > > > > So, how do I cull out the values I need? > > > > Thanks for reading this far. > > > > > > - Lee > > > > I found one problem, I'd forgotten to pass the xmlData to the > selectors, so, I assume, it was searching the web page.... >
It's all about the typos: for (var srow=1; srow <= cnt; srow++) { var fname = $j("row[selectionid*='"+srow+"'] field:nth-child(3)",dataXML).text(); };