JSON中的表格 [英] Table from JSON
本文介绍了JSON中的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个php脚本,该脚本基本上通过以下方式加载一个csv:
I've a php script which loads basically just one csv via:
echo json_encode(file(csvfile.csv, FILE_IGNORE_NEW_LINES));
输出是这样的:
["foo,bar,baz","foo, foo,bar","bla,bla,blubb"]
在我的基本html文件中,我以这种方式加载它:
In my basic html file I load it in this way:
<script>
$(document).ready(function(){
$.getJSON("myphpscript.php", function(data) {
filltable(data);
})
});
function filltable(jqxhr){
var table_obj = $('table');
$.each(jqxhr, function(index, item){
table_obj.append($('<tr id="'+item.id+'"><td>'+item.data+'</td></tr>'));
}).insertAfter('.table');
}
</script>
仅用 undefined 填充我的<table id="table"></table>
.
我的目标是获取包含1列的表:
My goal is it to get a table with 1 column containing:
foo,bar,baz
foo, foo,bar
bla,bla,blubb
指定分隔符后,我的js函数应爆炸每行和更多列. 这是我第一次尝试使用javascript和json.非常感谢
After specify a delimiter my js-function should explode each line and more columns. This is my first attempt with javascript and json. Thank you very much
固定函数调用(感谢VisioN).现在object.length可以,但是表仍未定义
Fixed function call (Thanks VisioN) . object.length is now ok, but the table is still undefinied
推荐答案
我认为您可能要使用
table_obj.append($('<tr id="'+index+'"><td>'+item+'</td></tr>'));
代替
table_obj.append($('<tr id="'+item.id+'"><td>'+item.data+'</td></tr>'));
这篇关于JSON中的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文