0

So I have an array returning from the function call @mappingFunctions.getFunctionNames(), and I'm passing it into a handlebars template, but nothing's happening.

    @$el.append(@template({
      column: columns
      functionNames: JSON.stringify(@mappingFunctions.getFunctionNames())
    }))

In another file -

  getFunctionNames: ->
    names = []
    functions = @get('functions')
    for name of functions
      names.push(name)
    return names

It seems like the each is not being run -

<select class="map-columns">
  {{#each column}}
    <option value="{{ this }}">{{ this }}</option>
  {{/each}}
</select>

<select class="map-functions">
  {{#each functionNames}}
    <option value="{{ this }}">{{ this }}</option>
  {{/each}}
</select>

Why?

praks5432
  • 5,732
  • 22
  • 76
  • 138
  • `JSON.stringify` makes a string, while `#each` expects an object. See the problem? You don't show what `columns` is, but I suspect it has the same or a similar issue. – Jon Aug 17 '13 at 21:05
  • @Jon handlebars each expects an array, not object – tsiki Aug 17 '13 at 21:07
  • so, I've passed in an array - and it still isn't working...or do you mean it has to be an object? – praks5432 Aug 17 '13 at 21:08
  • nvm - it works - post it up as an answer – praks5432 Aug 17 '13 at 21:08
  • @tsiki: [Wrong](http://stackoverflow.com/questions/9058774/handlebars-mustache-is-there-a-built-in-way-to-loop-through-the-properties-of/17516837#17516837). – Jon Aug 17 '13 at 21:09
  • @Jon my apologies, haven't has the chance to use 1.0 extensively. – tsiki Aug 17 '13 at 21:11
  • @tsiki: No problem. "expects an object" was not spot on either, an array is of course better -- the `JSON.stringify` threw me off there (started thinking about objects). – Jon Aug 17 '13 at 21:15
  • @praks5432: Added an answer. – Jon Aug 17 '13 at 21:17

1 Answers1

0

You are passing a string value to the template because that's what JSON.stringify produces. For functionNames the fix would be to remove the JSON.stringify and pass the straight array instead.

I 'm not sure what the deal with columns is, but it could very well be something similar.

Jon
  • 396,160
  • 71
  • 697
  • 768