2

I get the data from server every 10 seconds as

var data = { response: {}, calls: 0 };
    var poller = function() {
        $http.get('http://localhost:8080/monitoring/rest/graph/temperature').then(function(r){
            data.response = r.data;
            console.log(r.data);
            extractTemperatureReadings(r.data)
            data.calls++;
            $timeout(poller, 10000)
        });
    }
    poller();

and then I want to extract certain values which I do as

function extractTemperatureReadings(apiResponse) {
    var readings = {}
    readings['reading'] = apiResponse.map(function(value){value.reading})
    readings['dateTime'] = apiResponse.map(function(value){value.dateTime})

    console.log('Temperature reading: ' + JSON.stringify(readings))
    return readings
}

However on Browser console.log, I see

[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
monitoring.js:64 Temperature reading: {"reading":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"dateTime":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]}

where each Object when I click, I get

0: Object
dateTime: "2015-08-31 19:56:28.335000"
moduleId: "110010 "
reading: "400"
__proto__: Object

What is wrong with my code?

1 Answer 1

3

You never return from your .map calls

readings['reading'] = apiResponse.map(function(value){ return value.reading })
readings['dateTime'] = apiResponse.map(function(value){ return value.dateTime })

Also, you don't have to stringify your object to see it in the console with preceding text, simply do:

console.log('Temperature reading: ', readings)
Sign up to request clarification or add additional context in comments.

1 Comment

I am still in my Scala senses :(. Thanks @tymeJV

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.