0

I have this helper with a cursor.forEach inside.

    Template.profileTags.helpers({

        tag:function(){

            var tags = tikiTags.find({}).fetch()
            var user = tikiUser.find({}).fetch()

            //get the user tags
            var userTags = user[0].tags

            tags.forEach(function(doc, index, array){

                //this generates an Exception in template helper: .tag@http://localhost:3000/client/block/profile/profile.js
                console.log(userTags)

                //this works ok and i get the .tags array
                console.log(user[0].tags)

                array[index].isActive = "active"

            })

            return tags

        }

    })

Why does the first console.log() generate an exception? The second console.log() works but now i'm getting the user's tags 3 times, and that's not very efficient?

thx,

kevinius
  • 4,232
  • 7
  • 48
  • 79
  • What does your data look like? Have you tried logging **userTags** immediately after the **var** is initialized? (before the **forEach** block) – Chip Castle Jan 11 '15 at 19:19
  • thx... if i log it before the forEach it shows me the value, so that's correct. But it seems the exception is coming from the declaration: var userTags = user[0].tags generates the exception, while var userTags = user[0] does not. – kevinius Jan 12 '15 at 09:29
  • That's probably because it doesn't contain a **tags** property. Would you please post the data itself? Also, although semicolons aren't always necessary, please consider adding them to your JS, just so there aren't any hiccups, as described here: http://stackoverflow.com/questions/444080/do-you-recommend-using-semicolons-after-every-statement-in-javascript. Also, http://jslint.com can help you with this. – Chip Castle Jan 12 '15 at 17:01

0 Answers0