PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/4. Backbone Kata/BackboneKata1/App.js

https://bitbucket.org/farmas/coding-katas
JavaScript | 53 lines | 41 code | 12 blank | 0 comment | 0 complexity | 256f8f0e243b37c33403915e0e7c2977 MD5 | raw file
  1. var Issue = Backbone.Model.extend({
  2. });
  3. var IssueView = Backbone.View.extend({
  4. tagName: 'li',
  5. initialize: function(){
  6. this.template = _.template($('#issue').html());
  7. },
  8. render: function(){
  9. $(this.el).html(this.template(this.model.toJSON()));
  10. return this;
  11. }
  12. });
  13. var IssueCollection = Backbone.Collection.extend({
  14. model: Issue
  15. });
  16. var IssueCollectionView = Backbone.View.extend({
  17. tagName: "ul",
  18. initialize: function(){
  19. this.collection.bind('add', this.render, this);
  20. },
  21. render: function(){
  22. var $ul = $(this.el).empty();
  23. this.collection.each(function(i){
  24. $ul.append(new IssueView({model: i}).render().el);
  25. });
  26. return this;
  27. }
  28. });
  29. $(document).ready(function(){
  30. var issueCollection = new IssueCollection();
  31. var issueCollectionView = new IssueCollectionView({collection: issueCollection});
  32. $('#newIssueSubmit').click(function(evt){
  33. var issue = new Issue({
  34. title: $('#newIssueText').val(),
  35. priority: $('#newIssuePriority').find(':selected').val()
  36. });
  37. $('#newIssueText').val('');
  38. issueCollection.add(issue);
  39. });
  40. $('.issueList').append(issueCollectionView.render().el);
  41. });