javascript - Mongo document to array -


i'm getting document mongodb in meteor this:

template.subtasks.helpers ({    subelement: function (){         var sublen = todoscol.find(this);       // var sublen2 = ????        return sublen2;   }   }); 

it works great, sublen returns object. when i'm, trying convert array (for example like:

var sublen2 = sublen.toarray();

or

var sublen = todoscol.find(this).toarray();

or whole collection (without 'this'), doesn't work , "undefined not function" error in chrome console.

i tried

var sublen2 = sublen.propertyname;

since it's object, no luck.

what doing wrong?

thanks

edit:

i'm trying iterate on values stored in array in mongo document. want output them example separate div's. it's simple task list. tasks iterating great, i'm trying output subtasks assigned specific task. subtasks stored in same document 'parent tasks' array of strings.

template:

<template name='subtasks'>     <div class='sub-output {{_id}}'>         {{#each subelement}}             <div class='sub-task {{_id}}'>                 {{subtask}}              </div>         {{/each}}     </div> </template> 

if todoscol collection, .find() method returns cursor - http://docs.meteor.com/#/basic/mongo-collection-find. cursor can used iterate through results efficiently , reactively using {{each}}.

as documentation explains, if want results of find() call, need call .fetch() - learn more @ http://docs.meteor.com/#/full/mongo_cursor


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -