#714
A simple playground for learning backbone.js without having to install or configure anything yourself.
HTML
<script src="http://documentcloud.github.com/underscore/underscore.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone.js"></script>
<script src="https://getfirebug.com/firebug-lite.js"></script>
JavaScript
var FileModel = Backbone.Model.extend({
path: 'someDefaultPath'
});
var FileCollection = Backbone.Collection.extend({
model: FileModel,
fileList: [],
isNew: function(filePath) {
if($.inArray(filePath, this.fileList) === -1) {
return false;
} else {
return true;
}
},
add: function(fileModel) {
var filePath = fileModel.get('path');
if( !this.isNew( filePath ) ) {
console.log("pushing a new file: " + filePath);
this.fileList.push(filePath);
} else {
console.log('file is already in list');
};
},
getFileList: function(){
return this.fileList;
}
});
var file1 = new FileModel({
path: '/somePathInServer123'
});
var file2 = new FileModel({
path: '/somePathInServer222'
});
var file3 = new FileModel({
path: '/somePathInServer333'
});
var myFileCollection = new FileCollection();
myFileCollection.add(file1);
myFileCollection.add(file2);
myFileCollection.add(file3);
myFileCollection.add(file1);
myFileCollection.add(file2);
myFileCollection.add(file3);
console.log( myFileCollection.getFileList() );