【发布时间】:2017-05-31 18:39:01
【问题描述】:
您好,我在显示从数据库中获取的 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 数据中显示产品名称?
【问题讨论】:
-
您想获取所有产品名称并在某处显示它们吗?
-
是的,我也想在选择菜单的选项中显示所有条形码,我想附加所有条形码选项。
标签: jquery json ajax codeigniter