2015-10-13 53 views
0

我想更新每行的每第三列使用數據從ajax調用中每行的第一列計算得出。我無法獲得$ .map或$ .each行,以便使用從$ .post請求生成的數據更新每行的每第三列。

var relationsToSeller = []; 

$('tr td:first-child').find('a').each(function(index, value) { 
    var portfolioArray = $(this).attr('href').split('&id='); 

    //Ajax request to get username's relation to seller and append text 
    $.post('http://localhost/public/?r=matchTable/relationtoseller', { portfolioId: portfolioArray[1] }) 
     .done(function(data) { 


     //$('tr td').first().text(data); 
     var relationToSeller = data; 
     relationsToSeller.push(relationToSeller); 
     //console.log(relationsToSeller); 


     // Therefore, convert it to a real array 
     var realArray = $.makeArray(relationsToSeller) 

     // Now it can be used reliably with $.map() 
     $.map(realArray, function(val, i) { 
      // Do something 
      $('tr:eq(i) td:eq(2)').text(val); 
     }); 


     //$.each(relationsToSeller, function(index, value) { 
      //var pop = relationsToSeller.pop(); 
      //console.log(relationsToSeller); 
      //console.log(index + ': ' + value); 
     // console.log($('tr:eq(index) td:eq(2)').text(value)); 
      //$('tr:eq(5) td:eq(2)').text(value); 
      //$('tr:eq(index) td:eq(2)').text(value); 
     //}); 

    }); 

}); 
+0

' 'TR:等式(1)TD:EQ(2)''你知不知道'我'是在一個字符串的中間,對嗎?所以它不會真的用索引取代'i'? –

回答

0

我能得到它的工作,做我想做的與此代碼:

var relationsToSeller = []; 

$('tr td:first-child').find('a').each(function(index, value) { 
    var portfolioArray = $(this).attr('href').split('&id='); 

    //Ajax request to get username's relation to seller and append text 

    $(this).parent().next().next().find('a').load('http://localhost/public/?r=matchTable/relationtoseller', { portfolioId: portfolioArray[1] }); 

}); 
相關問題