Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Render mustache template inside a mustache helper and add can.Components

$
0
0
I keep getting this error when I try the following:

Error : Uncaught TypeError: Cannot convert object to primitive value

In my main template I loop through my content items and depending on the type it has to render a different template and create can.Components

main-template:
  1. {{#content}}
  2. {{contentTemplateHelper .}}
  3. {{/content}}
main can.Control:
  1. self.element.html(can.view('startup_views_startup_mustache', {
  2. content : self.content
  3. }, {
  4. contentTemplateHelper : function(contentType, options) {
  5. if(contentType.attr('type') === 'checkbox') {
  6. return can.mustache.safeString(can.view("content-checkbox_mustache", {item : contentType}));
  7. } else ....
  8. }
  9. }));
content-checkbox.mustache
  1. <content-checkbox {{data 'model'}}></content-checkbox>

can.Component
  1. can.Component.extend({
  2. tag: 'content-checkbox',
  3. template: can.view('components_views_content-checkbox'),
  4. scope : {},
  5. events: {
  6. 'init' : function() {
  7. this.scope = this.element.data('model');
  8. },
  9. '.checkbox click' : function(el) {
  10. if(this.scope.status !== 'disabled') {
  11. this.scope.attr('status', (this.scope.status === 'checked' ? '' : 'checked'));
  12. }
  13. }
  14. }
  15. });

Is this a correct way of working?
- template inside a helper
- adding the data model on the component tag
- ...




Viewing all articles
Browse latest Browse all 3491

Trending Articles