hi team
i will need your help again
based on this query :
function getRecords() {
window.df.apis.NOUNOUDB.getRecords({"table_name":"heure", "fields":"SUM(repas)"}, function (response) {
document.getElementById("nombreheure").innerHTML = JSON.stringify(response);
}, function(response) {
document.getElementById("nombreheure").innerHTML = window.app.getErrorString(response);
});
};
i get this in my nombreheure div:
{“record”:[{“SUM(repas)”:“37”}]}
How can i arrange my code to just show the result : 37 ??
thanks in advance & have a nice weekEnd;
regards,
Try this:
var value = response.record[0]["SUM(repas)"];
tod
like this?
function getRecords() {
window.df.apis.NOUNOUDB.getRecords({"table_name":"heure", "fields":"SUM(repas)"}, function (response) {
var value = response.record[0]["SUM(repas)"];
document.getElementById("nombreheure").innerHTML = value;
}
thanks
That looks ok, assuming only one record is returned. There could be zero records (empty array) or multiple records. You need to handle those cases based on response.record.length.
thanks tod
i will try it
regards
hi todd thanks again
works with code like this :
// CRUD
function getRecords() {
window.df.apis.NOUNOUDB.getRecords({"table_name":"heure", "fields":"SUM(repas)"}, function (response) {
showrepas(response);
}, crudError
);
}
// ui
function showrepas (json) {
var valuerepas = json.record[0]["SUM(repas)"];
$("#nombreheure").html(valuerepas);
}