I am sent the assistance by many advisors in stackoverflow, In part of my problem is solved but a few problems are remained.
I consult the answer and I has try to solve the problem as a result from it i understood the javascript namespacing pattren.
A namespacing pattern to avoid polluting the global namespace.
More details on this namespacing pattern
How do I declare a namespace in JavaScript?
I suffer from problem that global variable is created successfully however, i don't handle the generated variable.
collecton.js
var app = app || {};
(function () {
'use strict';
var collections = app.Collection = app.Collection || {};
collections.VideoLists = Backbone.Collection.extend({
model: app.Model,
initialize: function(){
console.log('load Collection');
}
});
app.Collection = collections.VideoLists;
})();
model.js
var app = app || {};
(function() {
'use strict';
var models = app.Model = app.Model || {};
models.Video = Backbone.Model.extend({
initialize: function(){
console.log('model create');
},
defaults:{
id : "1",
url : "/assets/videos/call/MOV01718.mp4",
imgSrc : "assets/img/call/1_thumbnail.png",
title: "call situation conservation"
}
});
app.Model = new models.Video();
})();
router.js
listRoute: function(id) {
//generate the collection using the listsection
var videoList = this.collection;
var getId = parseInt(id);
switch (getId) {
case 1:
new videoList([
{
id : "1",
url : "/assets/videos/call/MOV01718.mp4",
imgSrc : "assets/img/call/1_thumbnail.png",
title: "call situation conservation"
},
{
id : "2",
url : "/assets/videos/call/MOV01722.mp4",
imgSrc : "assets/img/call/2_thumbnail.png",
title: "call situation conservation"
}
]);
break;
//app.router init part
initialize: function() {
// create the layout once here
this.layout = new views.Application({
el: 'body',
});
// create model and collection once here
this.model = app.Model;
this.collection = app.Collection;
}
Please see the below picture
I think the generation has been done properly.
But I do not understand why I get this error.
I tried at first
1. Don't generate collection with new function
(as current my source)
2. Create variable videoList
as Object.
3. Stores Collection
in a variable.
4. Use collection.create function.
For example, list.create({id:'dasdsad'});
However, this attempt eventually yielded the same result.
How can i solve them?