Javascript 埃图恩; } } //找不到身份证。错误消息。 忙=假//如果getJSON调用失败,还应将busy=false设置为false。 }); } 函数writeItem(项){ //由findId作为回调函数调用。 var write='Cod'+item.cd+'Name'+item.nm_客户+'cpf'+item.cpf+''; $(“#mytable”).append(write);//附加到现有表数据。 }
请注意,有些错误条件未经示例处理。我将把这留给你和你的实施 使用开源项目jinqJs,您可以做到这一点Javascript 埃图恩; } } //找不到身份证。错误消息。 忙=假//如果getJSON调用失败,还应将busy=false设置为false。 }); } 函数writeItem(项){ //由findId作为回调函数调用。 var write='Cod'+item.cd+'Name'+item.nm_客户+'cpf'+item.cpf+''; $(“#mytable”).append(write);//附加到现有表数据。 },javascript,jquery,json,Javascript,Jquery,Json,请注意,有些错误条件未经示例处理。我将把这留给你和你的实施 使用开源项目jinqJs,您可以做到这一点 var result = jinqJs().from('http://....').where('id = ' + cli).select(); 这些错误告诉了你所有的内容,函数 FIDDO 不在TraceEI中回答你所得到的实际错误,但是要考虑输出这样的数据的另一件事是“代码>数组。原型。map < /COD>或数组。您的aaData是一个数组,映射是将数据作为一组数组映射到表中的一种非常
var result = jinqJs().from('http://....').where('id = ' + cli).select();
这些错误告诉了你所有的内容,函数<代码> FIDDO 不在TraceEI中回答你所得到的实际错误,但是要考虑输出这样的数据的另一件事是“代码>数组。原型。map < /COD>或<代码>数组。您的
aaData
是一个数组,映射是将数据作为一组数组映射到表中的一种非常干净的方法。@Rob Scott如何解决这个问题?你能指引我吗?我忘了标注尺寸,但我是jquery新手。@Josh,是的,我忘了在这里标注尺寸,但我使用的另一个页面有$.each()来编写我的主表。我会更新这个问题。Thanks@charlietfl总体来说,这是一个草率的代码——OP可以计算出逻辑,我只是告诉他们这个错误是什么。我理解你在那里试图解释我的意思。但是我不需要写所有客户机的数据信息,而是需要写一个客户机的信息。例如,如果我单击ID=3的客户机“James”,我只需要从ID=3的字符串中写入信息,并从其他客户机写入nto。我希望我现在能解释得更清楚一点=谢谢!这解决了我的问题=D,而且,如果您可以提供其他内容来改进这一点,那将非常棒,因为我是jquery新手,等等。。但是谢谢你!我来看看。谢谢你的建议
{
"aaData": [
{
"id":0,
"cd":"C-0001",
"nm_cliente":"John",
"cpf":"000.111.222-33",
"nm_pai":"Nome Completo",
"nm_mae":"Nome Completo",
"tel":"00-9966-6699",
"cidade":"city",
"estado":"estate"
},
//rest of my code here...
]
}
$(document).ready(function() {
var url = "data/c_fisico.json";
var cli; //getting the client id from the url. rest of the code is in other page
$.getJSON(url, function(data) {
var rows = '';
data.aaData.forEach(function(aa) {
rows += '<tr><td>Code</td><td>' + aa.cd + '</td></tr>' +
'<tr><td>Name</td><td>' + aa.nm_cliente + '</td></tr>' +
'<tr><td>cpf</td><td>' + aa.cpf + '</td></tr>';
});
$('#mytable').html(rows);
});
});
$(document).ready(function() {
var url = "data/c_fisico.json";
var cli; //getting the client id from the url. rest of the code is in other page
$.getJSON( url, function(json_data) {
var categoryArray = json_data.aaData;
for (var i = 0; i < categoryArray.length; i++) {
if (categoryArray[i].cd == cli) {
writeItem(categoryArray[i]); //Pass the matching object to writeItem.
return;
}
}
});
});
function writeItem(item) {
//"item" has already been parsed to an object, it's no longer a JSON string.
var write += '<tr><td>Cod</td><td>' + item.cd + '</td></tr><tr><td>Name</td><td>' + item.nm_cliente + '</td></tr><tr><td>cpf</td><td>' + item.cpf + '</td></tr>';
$('#mytable').html(write);
}
var my_data = null;
$(document).ready(function() {
var url = "data/c_fisico.json";
//You should add error handling in here, so you know if the JSON file wasn't available.
$.getJSON( url, function(json_data) {
my_data = json_data.aaData;
$("#some_button").attr("disabled", false); //JSON data has loaded, so enable our button.
});
$("#some_button").attr("disabled", true); //Disable our button so the user can't click it until JSON is loaded.
$("#some_button").on("click", function() {
var id = //Figure out what ID you want to load here.
writeItem(id); //Call the write function.
});
});
function findId(id) {
if (my_data === null) { return null; } //JSON hasn't been retrieved yet, so we can't find anything.
for (var i = 0; i < my_data.length; i++) {
if (my_data[i].cd == id) {
return my_data[i];
}
}
return null; //The requested ID wasn't found.
}
function writeItem(id) {
var item = findId(id);
if (item === null) {
//The ID wasn't found or JSON isn't available.
//Show error message or whatever you'd like.
return;
}
var write = '<tr><td>Cod</td><td>' + item.cd + '</td></tr><tr><td>Name</td><td>' + item.nm_cliente + '</td></tr><tr><td>cpf</td><td>' + item.cpf + '</td></tr>';
$('#mytable').append(write); //Appends to existing table data.
}
var busy = false;
$(document).ready(function() {
var url = "data/c_fisico.json";
//You should add error handling in here, so you know if the JSON file wasn't available.
$.getJSON( url, function(json_data) {
my_data = json_data.aaData;
$("#some_button").attr("disabled", false); //JSON data has loaded, so enable our button.
});
$("#some_button").on("click", function() {
var id = //Figure out what ID you want to load here.
findId(id, writeItem); //Call the find function and tell it to call the write function when done.
});
});
function findId(id, callback) {
if (busy) { return; } //Don't call again if we're already in the process of another call.
busy = true;
$.getJSON( url, function(json_data) {
var categories = json_data.aaData;
for (var i = 0; i < categories.length; i++) {
if (categories[i].cd == id) {
//Item was found, so pass the object to our callback.
callback(categories[i]);
busy = false; //You should also set busy = false if the getJSON call fails.
return;
}
}
//ID wasn't found. Error message.
busy = false; //You should also set busy = false if the getJSON call fails.
});
}
function writeItem(item) {
//Gets called by findId as a callback function.
var write = '<tr><td>Cod</td><td>' + item.cd + '</td></tr><tr><td>Name</td><td>' + item.nm_cliente + '</td></tr><tr><td>cpf</td><td>' + item.cpf + '</td></tr>';
$('#mytable').append(write); //Appends to existing table data.
}
var result = jinqJs().from('http://....').where('id = ' + cli).select();