mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-06-27 16:00:04 +08:00
Add Backbone models, collection, views
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
var app = app || {};
|
||||
|
||||
$(function(){
|
||||
|
||||
var tasks = [
|
||||
{content: 'helloworld'},
|
||||
{content: 'wtf'},
|
||||
{content: 'rotterdam'},
|
||||
{content: 'hahahah'}
|
||||
];
|
||||
|
||||
new app.ListView(tasks);
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
var app = app || {};
|
||||
|
||||
(function() {
|
||||
|
||||
app.List = Backbone.Collection.extend({
|
||||
|
||||
model: app.Task
|
||||
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,14 @@
|
||||
var app = app || {};
|
||||
|
||||
(function() {
|
||||
|
||||
app.Task = Backbone.Model.extend({
|
||||
|
||||
defaults: {
|
||||
parent_id: '',
|
||||
content: ''
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,26 @@
|
||||
var app = app || {};
|
||||
|
||||
(function() {
|
||||
|
||||
app.ListView = Backbone.View.extend({
|
||||
|
||||
el: $("#main .children"),
|
||||
initialize: function(initialTasks) {
|
||||
this.collection = new app.List(initialTasks);
|
||||
this.render();
|
||||
},
|
||||
render: function() {
|
||||
this.collection.each(function(task) {
|
||||
this.renderTask(task);
|
||||
}, this);
|
||||
},
|
||||
renderTask: function(task) {
|
||||
var taskView = new app.TaskView({
|
||||
model: task
|
||||
});
|
||||
this.$el.append(taskView.render().el);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,18 @@
|
||||
var app = app || {};
|
||||
|
||||
(function() {
|
||||
|
||||
app.TaskView = Backbone.View.extend({
|
||||
|
||||
tagName: 'li',
|
||||
template: $('#taskTemplate').html(),
|
||||
|
||||
render: function() {
|
||||
var tmpl = _.template(this.template);
|
||||
this.$el.html(tmpl(this.model.toJSON()));
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}());
|
||||
Reference in New Issue
Block a user