Reputation: 4009
I have a click handler on a jQuery datatables table row - if you click a row a new dialog is launched. However i am having soem problems getting the ID which I need to pass to my ajax function which launches the pop up.
I have the line of code below:
var rowData = carTable.fnGetData(event.target.parentNode);
If I then do the following.
var json = JSON.stringify(rowData);
If I then alert(json); I get the following pop up
{"ExtensionData":{}, "CarRegNo" : "ABC 123",
"CarNumber": "98765", "CarID" : 1234,
"CarName" : "BMW", "CarFaults" : 2,
"CarDealerID" : 16, "DealerName" : "WeSellCars"}
The only value I need is the 1234 from CarID? How can I easily get this value?
I tried the following so far with no luck - so without doing the JSON.stringify I just got the key from rowData - when I just alerted the key I could see all the different values, i.e CarID, CarRegNo - however then I tried to alret the actual value of CarID with the code below - but no response comes back - the browser just seems to hang.
for (var key in rowData) {
alert(key);
if (key == 'CarID')
alert(rowData[0][key]);
}
Upvotes: 0
Views: 2168
Reputation: 38345
Should literally be just:
var carId = rowData.CarId;
The rowData
variable already contains the single object, and CarId
is a property of it.
Upvotes: 2