i have json data like this :
[{"id_asset":"4b5c2a52-a4fb-44f3-8b15-be369878ff1e","id_safety":{"id_safety":"64fa5f8b-44c2-4906-9bf8-27f826e026a5","referensi":"default","keterangan":"default","safety_procedure":"default","alat_safety":"default"},"asset_name":"roll","serial":"r129","asset_code":"C1-R1","parent_code":"C1-R11","purchase_date":"2020-03-03","grup":"bahan bakar","model":"CR123","location":"bengkel","asset_tag":"C1222","warranty":12.0,"safety_referensi":"default","vendor":"daeyang","consume":0,"stok":0,"end_balance":0,"price":1111.0},{"id_asset":"5ef6c6f2-9cfd-475a-8d21-5ade18d2fd20","id_safety":null,"asset_name":"C01829XX","serial":"C1-R11","asset_code":"xxx","parent_code":"","purchase_date":"2020-02-24","grup":"bahan baku sipil","model":"bengkel","location":"C1111","asset_tag":"xx","warranty":0.0,"safety_referensi":"daeyang","vendor":"sss","consume":0,"stok":0,"end_balance":0,"price":1111111.0}]
and i want get value from id_safety, (example: id_safety:64fa5f8b-44c2-4906-9bf8-27f826e026a5) but when i click datatable always return undifined
this is js for select value :
var dat = $('#tabelass').DataTable().row('.selected').data();
console.log(dat );
alert("id_asset:" + dat ['id_asset'] + "\id_safety:" + dat ['id_safety.id_safety']);
You have a small issue in here. Just replace this in your code:
dat ['id_safety.id_safety']
with this:
dat['id_safety']['id_safety']
as dat['id_safety']
retuns the inner object in this format:
{id_safety: "64fa5f8b-44c2-4906-9bf8-27f826e026a5", ... }
and in order to access the id_safety
property in this object, you will need to do like:
dat['id_safety']['id_safety']
// returns "64fa5f8b-44c2-4906-9bf8-27f826e026a5"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.