Each loop in html not working - pls help!

CAn the set fail if I have not implemented the server method for synch behaviour?

I have converted my server method from asnyc to sync

    var convertAsyncToSync  = Meteor.wrapAsync( HTTP.get ),
        camListForUser = convertAsyncToSync( apiurl, {} );

but still get the error in the client
Exception in delivering result of invoking ‘cctvdetails’: TypeError: Cannot read property ‘set’ of undefined
at http://localhost:3000/app/client/video/video.js?7753a00427942d9c9ee3fdf418a30b4ff4d7a186:47:41
at null._callback (http://localhost:3000/packages/meteor.js?431e407b21bf81d79061795e4fce958bea956e90:1007:22)
at _.extend._maybeInvokeCallback (http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:3508:12)
at _.extend.receiveResult (http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:3528:10)
at .extend.livedata_result (http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:4639:9)
at onMessage (http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:3373:12)
at http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:2742:11
at Array.forEach (native)
at Function.
.each.
.forEach (http://localhost:3000/packages/underscore.js?fa590de5090ceb4a42555b48562fd8f8e7035758:157:11)
at self.socket.onmessage (http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:2741:11)

this is my oncreated code. Can you pls help understand why the ReactiveVar decalration is not working?

Template.video.onCreated(function(){
this.urlList = new ReactiveVar();

    var tokenId = '';

    tokenId = Cookie.get('Token');

    Meteor.call('cctvdetails', tokenId, function (error, result) {
        if (error) {
            console.log(error);
            //trigger an error message and raise an ALARM
            //$('#autoclosable-btn-danger').prop("disabled", true);
            $('.alert-autocloseable-danger').show();

            $('.alert-autocloseable-danger').delay(5000).fadeOut("slow", function () {
                // Animation complete.
                // $('#autoclosable-btn-danger').prop("disabled", false);
            });
        } else {
            if (result == 'noDataReturnedByAPI') {
                //$('#autoclosable-btn-warning').prop("disabled", true);
                $('.alert-autocloseable-warning').show();

                $('.alert-autocloseable-warning').delay(5000).fadeOut("slow", function () {
                    // Animation complete.
                    // $('#autoclosable-btn-warning').prop("disabled", false);
                });
            }
            else {
                $('.alert-autocloseable-success').show();

                $('.alert-autocloseable-success').delay(5000).fadeOut("slow", function () {
                    // Animation complete.
                    // $('#autoclosable-btn-warning').prop("disabled", false);
                });
                console.log('result[1]: ' + result[1].domainport)
                this.urlList.set(result);

                //urlList = result;
                //console.log('onRendered call: ' + urlList.length)
                //console.log('result domain port: ' + urlList);
                var numberOfCameras = urlList.length;
                Session.set('cameraCount', numberOfCameras);
                if (numberOfCameras == 1) {
                    Session.set('templateType', 'singleCamView');
                }
                else if (numberOfCameras > 1 && numberOfCameras <= 4) {
                    Session.set('templateType', 'fourCamView');
                }

                else if (numberOfCameras > 4 && numberOfCameras <= 9) {
                    Session.set('templateType', 'nineCamView');
                }
                else if (numberOfCameras > 9) {
                    Session.set('templateType', 'moreThanNineCams');
                }
                console.log('inside the else: ' + urlList[1].domainport)

            }

        }
        //return urlList;
    });

})

this is my helper

Template.body.helpers({
    urlList1: function(){
        return Template.instance().urlList.get();
    },

Your this.urlList.set(result); line is not scoped correctly for this (one reason I was using ES2015 syntax). What you should do is:

Template.video.onCreated(function() {
  this.urlList = new ReactiveVar();
  var self = this;
  // ... then around line 37 ...
        self.urlList.set(result);

Also, later on in your code, you are referring another urlList, the definition of which you have commented out (and really needs a var to scope it locally), so should be (something like):

            var urlList = result;
            //console.log('onRendered call: ' + urlList.length)
            //console.log('result domain port: ' + urlList);
            var numberOfCameras = urlList.length;
            Session.set('cameraCount', numberOfCameras);
            if (numberOfCameras == 1) {
                Session.set('templateType', 'singleCamView');
            }
            else if (numberOfCameras > 1 && numberOfCameras <= 4) {
                Session.set('templateType', 'fourCamView');
            }

            else if (numberOfCameras > 4 && numberOfCameras <= 9) {
                Session.set('templateType', 'nineCamView');
            }
            else if (numberOfCameras > 9) {
                Session.set('templateType', 'moreThanNineCams');
            }
            console.log('inside the else: ' + urlList[1].domainport)

However, this naming of two different things with the “same” name is confusing, and I may have missed the point! :smile:

i have changed the name to something else now to get the length. However I still get the exception like below

eption in delivering result of invoking ‘cctvdetails’: ReferenceError: urlList is not defined
at http://localhost:3000/app/client/video/video.js?fd6329e3223685960f5ed855b018bb9ee694d4ae:65:63
at null._callback (http://localhost:3000/packages/meteor.js?431e407b21bf81d79061795e4fce958bea956e90:1007:22)
at _.extend._maybeInvokeCallback (http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:3508:12)
at _.extend.receiveResult (http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:3528:10)
at .extend.livedata_result (http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:4639:9)
at onMessage (http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:3373:12)
at http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:2742:11
at Array.forEach (native)
at Function.
.each.
.forEach (http://localhost:3000/packages/underscore.js?fa590de5090ceb4a42555b48562fd8f8e7035758:157:11)
at self.socket.onmessage (http://localhost:3000/packages/ddp-client.js?82da06d8e1ea6342d823b2c5c3be071e96108c70:2741:11)

modified code is like this

 Template.video.onCreated(function(){
        this.urlList = new ReactiveVar();
        var self = this;
        testlist = [];
        var tokenId = '';

        tokenId = Cookie.get('Token');

        Meteor.call('cctvdetails', tokenId, function (error, result) {
            if (error) {
                console.log(error);
                //trigger an error message and raise an ALARM
                //$('#autoclosable-btn-danger').prop("disabled", true);
                $('.alert-autocloseable-danger').show();

                $('.alert-autocloseable-danger').delay(5000).fadeOut("slow", function () {
                    // Animation complete.
                    // $('#autoclosable-btn-danger').prop("disabled", false);
                });
            } else {
                if (result == 'noDataReturnedByAPI') {
                    //$('#autoclosable-btn-warning').prop("disabled", true);
                    $('.alert-autocloseable-warning').show();

                    $('.alert-autocloseable-warning').delay(5000).fadeOut("slow", function () {
                        // Animation complete.
                        // $('#autoclosable-btn-warning').prop("disabled", false);
                    });
                }
                else {
                    $('.alert-autocloseable-success').show();

                    $('.alert-autocloseable-success').delay(5000).fadeOut("slow", function () {
                        // Animation complete.
                        // $('#autoclosable-btn-warning').prop("disabled", false);
                    });
                    console.log('result[1]: ' + result[1].domainport)
                    self.urlList.set(result);
                    var testlist = result;
                    //urlList = result;
                    //console.log('onRendered call: ' + urlList.length)
                    //console.log('result domain port: ' + urlList);
                    var numberOfCameras = testlist.length;
                    Session.set('cameraCount', numberOfCameras);
                    if (numberOfCameras == 1) {
                        Session.set('templateType', 'singleCamView');
                    }
                    else if (numberOfCameras > 1 && numberOfCameras <= 4) {
                        Session.set('templateType', 'fourCamView');
                    }

                    else if (numberOfCameras > 4 && numberOfCameras <= 9) {
                        Session.set('templateType', 'nineCamView');
                    }
                    else if (numberOfCameras > 9) {
                        Session.set('templateType', 'moreThanNineCams');
                    }
                    console.log('inside the else: ' + urlList[1].domainport)

                }

            }
            //return urlList;
        });

    })

sorted it sorry my bad coding

Cool :smile:

You do not need to do this. The HTTP methods will execute natively in synchronous mode on the server if you do not specify a callback: http://docs.meteor.com/#/full/http_call

On the server, this function can be run either synchronously or asynchronously. If the callback is omitted, it runs synchronously and the results are returned once the request completes successfully.