javascript - Validate models with Backbone.js -


Trying to invent your own Todo List with the help of books and tutorials. My problem is that when you If ah add, then my model should be valid, if the input comes before presenting with some text. I have made a valid mathis but it does not work and I do not know how to track the error, I appreciate if you can help me find my error

Model:

  WRT Task = backbone.model.andend ({valid: function (ethers) {if (et; attitital)} {return "no title of work";}}}); Var function = new task;  

Archive:

var function = backbone. compilation. Extension ({model: work}); Var = new tasks ([{title: 'my work'}, {title: 'my task 1'}, {title: 'my task 2'}, {title: 'my task 3'}]);

View:

  var TaskView = backbone.View. Extension ({tagname: "li", template: _template ($ ('(#' function) '). HTML (), initialize: function () {this.model.on ("change", this.render, This);}, render: function () {var template = this.template (this.model.TJSON ()); $. El.html (template); return it;}, Event: {'click .icon-checkbox ':' ToggleState '}, ToggleState: Function (e) {var $ checkbox = $ (e .target); $ checkbox.toggleClass (' icon-checkbox-unchecked ');}}); Var TasksView = Backbone.View.extend ({el: '#tasks', initialize: function () {this.render (); this.collection.on ('add', this.addOne, this);}, render : Function () {this.collection.each (this.addOne, this); return it;}, addOne: function (task) {var Taskview = new workview ({model: work}); $. El.append ( TaskView) .render () .l);}}}; Var AddTask = Backbone.View.extend ({el: '#todos', Incidents: {'click #add': 'addTask'}, addTask: function () {var workTitle = $ ('# inputTask'). Val ( ); $ ('#InputTask'). Val (""); var function = new task ({title: taskTitle}); // function model this.collection.add (task); // Add Model to Collection}} ); Var WorkView = New Work View ({Collection: Work}); Var addTask = new addTask ({archive: function});  

Edit:

I have realized that when you set or save information in the model, it's actually confirmation Does, but what I really want to do, checks that when a user submits a todo that if it comes with text or ini to model and render.

You do not actually call valid method () method. Have you seen in the backbone validation plugin? Works very clever.


Comments