app.js 816 B

1234567891011121314151617181920212223242526272829303132333435
  1. (function(){
  2. "use strict";
  3. var todos=[];
  4. var app=Backbone.View.extend({
  5. el: '#main',
  6. events: {
  7. 'click #addTodo': 'addTodo',
  8. 'longTap li': 'removeTodo'
  9. },
  10. template:_.template($('#todoTemplate').html()),
  11. addTodo:function(){
  12. var item=$("#todoVal");
  13. var val=item.val();
  14. if(val.length<2) return;
  15. todos.push(val);
  16. item.val('');
  17. $("#todoList").append(this.template({title:val}));
  18. },
  19. removeTodo:function(e){
  20. var item=$(e.target);
  21. todos.splice(todos.indexOf(item.html()),1);
  22. $(item).remove();
  23. },
  24. initialize:function(){
  25. }
  26. });
  27. $.afui.ready(function(){
  28. new app();
  29. });
  30. })(jQuery);