0

In my meteor app, I have a JSON file containing this list of languages : List of Language Codes in YAML or JSON?

Template.myProfile.helpers({
  isoLang: function(){
    return JSON.parse(Assets.getText("myfile.json"));
  }
});

<select>
{{#each isoLang}}
  whaterver i put here
{{/each}}
</select>

The problem is that no matter what i return in my helper, as soon as i save the file, my app template change to the login template (im using iron outer), and it don't understand how it's possible.

I tried to get my langauages list as a js object, but from the public folder or the myProfile subfolder (in client folder), it brings me the same problem, and no matter what i try, i never enter my {{#each}} condition.

What am i doing bad in my use of this json / js object ?

Thanks you, David

Community
  • 1
  • 1
David Panart
  • 656
  • 6
  • 20
  • I think the problem is because you are using `{{#each}}`. Each is meant for arrays. but that list of languages is a bunch of objects not in array format. so you'd have to convert it to an array of objects. Otherwise if you use `{{#with isoLang}}` you would access each group individually inside the with statement by doing `{{ab}}, {{aa}}, {{af}}` – SirCharlesWatson Apr 09 '15 at 19:21

1 Answers1

0

The List of Language Codes is neither a JSON array (missing square brackets) nor a (Mongo) cursor. Spacebar's #each is meant

To iterate over an array or database cursor (cf Meteor docs ):

So all you need to transform your JSON object into a JSON array. Here's a basic sketch:

var JsonObj= {"a":"1","b":"2","c":"3","d":"4"};
var array = []; 
var k = 0
for(var i in JsonObj) {
    if(JsonObj.hasOwnProperty(i)) {
         array[k++] = JsonObj[i]; 
         console.log(">> " + JsonObj[i])
    }
 }
 console.log(array);
Community
  • 1
  • 1
Steffo
  • 622
  • 5
  • 6