canjs model not populating mustache template

153 views Asked by At

I am very new to CanJs just started learning, I am struck with below problem not able to debug it.

I have model as below:

Localized = can.Model({
        findOne : 'GET /resources/localized'
    }, {
});

GET /resources/localized ---> fetches available localized languages.

And I have defined a component as below

can.Component({
    tag : 'preferences',
    template : initView,
    init: function() {
        console.log(locales);
    },
    scope : {
        locales: new LocalizedModel.findOne({})
    }
});

initView has mustache template as below:

<div class="form-group">
   <label>{{dateLayout}}</label>
      <select class="form-control" id="lang" name="lang"  can-change="save">
          {{#list locales.languageOptions}}
              <option value="{{name}}">{{name}}</option>
          {{/list}}
      </select>
</div>

But the problem is locales are not getting populate, I could see network call for /resources/localized, any pointers here could really help to understand this.

1

There are 1 answers

0
air_hadoken On BEST ANSWER

Be careful to use the correct naming, especially if you were reading up on both EJS and Mustache building from the CanJS documentation. The helper that iterates over a list is {{#each listref}}...{{/each}} in can.Mustache and can.Stache, where in can.EJS it is <% list(listref, function(item) { %>...<% }) %>. Using {{#list ...}} will likely not produce anything.