R
R
Roman Ogarkov2015-12-25 16:38:09
backbone.js
Roman Ogarkov, 2015-12-25 16:38:09

How to display collection?

Help bring collections.
There is a model:

define([
  'backbone.marionette'
  ],
function (Marionette) {
  return Backbone.Model.extend({
    defaults: {
      id: '',
      name: 'Отчёт',
      number: ''
    }
  });
});

There is a collection:
define([
  'backbone.marionette',
  'models/report-link'
  ],
function (Marionette, ReportLinkModel) {
  return Backbone.Collection.extend({
    model: ReportLinkModel
  });
});

There is an ItemView:
define([
  'underscore',
  'backbone.marionette',
  'models/report-link',
  'text!templates/tables/reportLink.hbs'
  ],
function (_, Marionette, ReportLinkModel, ReportLinkTpl) {
  return Backbone.Marionette.ItemView.extend({
    template: _.template(ReportLinkTpl),
    tagName: 'li',
    model: new ReportLinkModel,
    initialize: function () {
      this.render();
    }
  });
});

And there is a CollectionView:
define([
  'backbone.marionette',
  'views/item/report-link',
  'collections/report-links'
  ],
function (Marionette, ReportLinkItemView, ReportLinkCollection) {
  return Backbone.Marionette.CollectionView.extend({
    childView: new ReportLinkItemView,
    collection: new ReportLinkCollection({id: '1', name: 'Отчёт', number: '1'}),
    tagName: 'ul',
    initialize: function () {
      this.render();
      console.log(this.collection)
    }
  });
});

I'm calling:
new ReportLinkCollectionView;
I'm getting an error:
TypeError: t is not a constructor

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aen, 2015-12-25
@ogarich89

childViewis a reference to a class, not an instance. Remove new.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question