ogarich89
@ogarich89
Front-End Developer

Как вывести collection?

Помогите вывести коллекции.

Есть модель:
define([
	'backbone.marionette'
	],
function (Marionette) {
	return Backbone.Model.extend({
		defaults: {
			id: '',
			name: 'Отчёт',
			number: ''
		}
	});
});

Есть коллекция:
define([
	'backbone.marionette',
	'models/report-link'
	],
function (Marionette, ReportLinkModel) {
	return Backbone.Collection.extend({
		model: ReportLinkModel
	});
});

Есть 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();
		}
	});
});

И есть 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)
		}
	});
});

Вызываю:
new ReportLinkCollectionView;

Вылетает ошибка:
TypeError: t is not a constructor
  • Вопрос задан
  • 224 просмотра
Решения вопроса 1
aen
@aen
Keep calm and 'use strict';
childView - это ссылка на класс, а не на инстанс. Уберите new.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы