Ajax jQuery使用$.map/$.each更新每行的第三列,并使用从Yii中表的每行第一列计算的$.post结果
我试图使用从ajax调用中每行的第一列计算的数据来更新每行的第三列。我无法获取$.map或$.each行,以使用从$.post请求生成的数据更新每行的第三列Ajax jQuery使用$.map/$.each更新每行的第三列,并使用从Yii中表的每行第一列计算的$.post结果,ajax,Ajax,我试图使用从ajax调用中每行的第一列计算的数据来更新每行的第三列。我无法获取$.map或$.each行,以使用从$.post请求生成的数据更新每行的第三列 var relationsToSeller = []; $('tr td:first-child').find('a').each(function(index, value) { var portfolioArray = $(this).attr('href').split('&id='); //Ajax r
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);
//});
});
});
我能够让它工作,并使用此代码执行我想要的操作:
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] });
});
i
?