以编程方式将一些td附加到tr - jQuery AJAX JSON [英] Programmatically append some td to tr - jQuery AJAX JSON

查看:142
本文介绍了以编程方式将一些td附加到tr - jQuery AJAX JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b $我一直在寻找一些方法来追加td到tr使用jQuery表,而不知道我的json响应,在这个时候我已经达到了这个目的:

 函数getClientes(){
$ .ajax({
url:URL_BASE +Cliente,
类型:GET,
beforeSend:function(xhr){
xhr.setRequestHeader(Authorization,Basic+ btoa(hola+:+hola));
},
成功:function(data){
$ .each(data,function(index,value){
$('< tr>')。append(
$ .each(value ,函数(value,celda)
{
$('< td>).text(celda);
})
).appendTo('#table') ;
})
}
});
}

问题是我得到如下的.html输出:

 < table id =tableclass =table table-condensed> 
< tr>< / tr>
< tr>< / tr>
< / table>

所以这不是将td附加到tr上,我不想将它们手动追加我知道这很容易做到,但这对我来说更好,请帮助:D

解决方案

最后我创建了一行在每个循环中手动追加它,不是最好的答案,但它适用于我,谢谢所有答案:D

 函数getClientes (){
$ .ajax({
url:URL_BASE +Cliente,
type:GET,
beforeSend:function(xhr){
xhr。 setRequestHeader(Authorization,Basic+ btoa(hola+:+hola));
},
成功:函数(数据){
$ .each (数据,函数(索引,值){
var row = $(< tr />);

$ .each(value,function(value,celda)
{
row.append($('td>').text(celda));
});
$('#table')。append(row );
})
}
});
}


I've been looking for some way to append td to tr to table using jQuery without knowing anything about my json response, at this point in time I've reached this:

function getClientes(){
    $.ajax({
    url:URL_BASE+"Cliente",
    type:"GET",
    beforeSend: function (xhr) {
        xhr.setRequestHeader ("Authorization", "Basic " + btoa("hola" + ":" + "hola"));
    },
    success: function (data){
            $.each(data,function(index,value){
                $('<tr>').append(
                    $.each(value,function(value,celda)
                    {
                        $('<td>').text(celda);
                    })                      
            ).appendTo('#table');
            })
        }
    });     
}

The problem is that I'm getting my .html output like this:

<table id="table" class="table table-condensed">
   <tr></tr>
   <tr></tr>
</table>

So this is not appending the td to the tr, I do not want to append them mannually I know it is very easy to do it but this is way better for me, please help :D

解决方案

finally I created a row and append it manually in each loop, not the best answer but it works for me, thank you for all answers :D

function getClientes(){
$.ajax({
url:URL_BASE+"Cliente",
type:"GET",
beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Basic " + btoa("hola" + ":" + "hola"));
},
success: function (data){
        $.each(data,function(index,value){
        var row = $("<tr/>");                

                $.each(value,function(value,celda)
                {
                   row.append($('<td>').text(celda));
                });                      
        $('#table').append(row);
        })
    }
});     
}

这篇关于以编程方式将一些td附加到tr - jQuery AJAX JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆