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:
- {{#content}}
- {{contentTemplateHelper .}}
- {{/content}}
main can.Control:
- self.element.html(can.view('startup_views_startup_mustache', {
- content : self.content
- }, {
- contentTemplateHelper : function(contentType, options) {
- if(contentType.attr('type') === 'checkbox') {
- return can.mustache.safeString(can.view("content-checkbox_mustache", {item : contentType}));
- } else ....
- }
- }));
- <content-checkbox {{data 'model'}}></content-checkbox>
can.Component
- can.Component.extend({
- tag: 'content-checkbox',
- template: can.view('components_views_content-checkbox'),
- scope : {},
- events: {
- 'init' : function() {
- this.scope = this.element.data('model');
- },
- '.checkbox click' : function(el) {
- if(this.scope.status !== 'disabled') {
- this.scope.attr('status', (this.scope.status === 'checked' ? '' : 'checked'));
- }
- }
- }
- });
Is this a correct way of working?
- template inside a helper
- adding the data model on the component tag
- ...