Sunday 15 May 2011

javascript - wikipedia table parsing, loop issue -


So I'm trying to create a 'deck' array filled with the 'card' object, assigning the 'card' object is required. Forephone and back

.Front needs to include the cell of each row, the first column alias .back should include the rest of the information in each row.

'tr' = line

'tr td' = cell

  rowArray = [] deck = [] $ ('tooby'). Click (function () {var rows = $ (this) .find ('tr'); var cells = $ (this) .find ('tr td'); (w = 0; w; libraries; cells.length ; W ++) {if (cells [w] .innertext === undefined) {} ​​else {rowArray.push (cells [w]. Warintext)}} for (var I = 0; i & lt; rows. Length; i ++) {var card = {} var info = $ (line [i]). ('TD') var cardFront = info [0] card.front = $ (cardFront) for .text () Var x = 0; x & lt; cells.length; x ++) {if (cells [x]. WarringText === undefined) {// excludes all undefined cells} and {if (x% ( (Rows.length) / cells.length)! == 0) {// Filter the first column, so no double Aa not a card. C = [x] .intertext;} else {}}}; deck push (card);};});   

The problem I have is that returning for all card objects is the final cell.

ex. , When I click on the table with the list of USStates, all the cards. Back === 'Wyoming Territory'

The solution that I'm cutting StackOverflow can help me find: Get information from each row, on the appropriate card

When you iterate on cells (for (var x = 0; x & Lt; cells.length; x ++) ) You are running again on each cell in the table, the last of which is the Wyoming area instead you want to run again on information , In which the row given contains only cells.

  rowArray = [] deck = [] $ ('tobs'). (Function () {var rows = $ (this) .find ('tr'); var cells = $ (this) .find ('tr td'); (w = 0; w; lens; cells.length; w ++) {If (cells [w] .innerText === undefined) {} ​​Other {line airfare (cells [w] .intertext)}}; (var i = 0; i & lt; rows.length; i + +) {Var card = {} var info = $ (rows [i]). Find the var card ('TD' )Frint = info [0] card.front = $ (cardfront) .text () // Notice information = info Remove the cell before .slice (1); card.back = info.map (function (i, e) {return e.innerText}). ToArray (); // This row has the coating deck inside rows. (Card);}});    

No comments:

Post a Comment