您好,我有问题显示从数据库中提取的JSON数据的特定值,我只想显示产品名称上的输入文本如何做到这一点?我尝试过,但它说没有价值。如何从数据库中提取的json数据获取特定值?
这里是我的JSON代码: -
{"brcode":[{"id":"1","name":"Rolex Watch","description":"Rolex wrist watches","uom":"1000","brand":"1051","tax_id":"1","purchase_price":"5000","sale_price":"6000","barcode":"ROLEX5000","created_date":"2017-05-29 13:31:24","created_by":"1","updated_date":"2017-05-29 13:31:24","updated_by":"1","status":null},{"id":"3","name":"motorola X play","description":"Moto X play mobile phone","uom":"50","brand":"7845","tax_id":"1","purchase_price":"20000","sale_price":"25000","barcode":"MOTOXPLAY500","created_date":"2017-05-29 14:18:43","created_by":"0","updated_date":"2017-05-29 14:18:43","updated_by":"0","status":null},{"id":"4","name":" LG Smart LED TV","description":"Smart LED TV from LG","uom":"5","brand":"5420","tax_id":"1","purchase_price":"80000","sale_price":"100000","barcode":"LGSMART5012","created_date":"2017-05-29 15:39:35","created_by":"0","updated_date":"2017-05-29 15:39:35","updated_by":"0","status":null},{"id":"5","name":"Computer Intel","description":"Intel smart computer","uom":"1","brand":"1","tax_id":"1","purchase_price":"40000","sale_price":"50000","barcode":"INTELPC2123","created_date":"2017-05-29 17:59:31","created_by":"0","updated_date":"2017-05-29 17:59:31","updated_by":"0","status":null},{"id":"6","name":"DDR4 Ram","description":"Ram for computer","uom":"6","brand":"1","tax_id":"1","purchase_price":"4000","sale_price":"5000","barcode":"RAMDDR4","created_date":"2017-05-29 18:15:17","created_by":"0","updated_date":"2017-05-29 18:15:17","updated_by":"0","status":null}]}
这里是我的功能: -
function get_barcodes() {
$.ajax({
url: 'http://localhost/retail/main/ajax_barcodes/',
type: 'POST',
datatype: 'json',
data: { 'barcode': $('#brcode option:selected').val() },
success: function (data) {
// var brcodes = JSON.parse(data);
//console.log(brcodes);
//var brCodes = JSON.parse(data);
//var json = JSON.parse(data);
//console.log(brCodes.brcode);
//$("#product_items_opts").val(barcodes.brcode.name);
// console.log(json);
console.log(data);
}
});
// $('#prdct_barcode[' + product_barcode_counter + ']').each(function(){
// $('#prdct_barcode[' + product_barcode_counter + ']').change(function(){
// });
// });
}
请忽略我写只是为了检查值的评论部分。请告诉我如何从JSON数据显示产品名称?
是否想获取所有产品名称并将其显示在某个地方? – JSONGagnon
是的,我也想显示选择菜单的选项中的所有条形码,我想追加所有的条形码选项。 –