12345678910111213141516171819202122232425262728293031 |
- $(function () {
- // Create a model class.
- const TodoItem = Backbone.Model.extend({
- // RESTful web service, RoR flavor.
- urlRoot: '/server/todos'
- });
- // Create a model instance to load it by ID.
- const todoItem = new TodoItem({ id: 1 });
- // Access the server at /server/todos/1 (urlRoot + '/' + item.id).
- const x = todoItem.fetch({ async: false });
- // Manipulate attributes.
- const description = todoItem.get('description');
- todoItem.set('status', 'complete');
- // Save on server.
- todoItem.save();
- // Create a view class.
- const TodoView = Backbone.View.extend({
- render: function () {
- const html = '<h3>' + this.model.get('description') + '</h3>';
- $(this.el).html(html);
- }
- });
- // Create a view instance.
- const todoView = new TodoView({ model: todoItem });
- todoView.render();
- $('#app').html(todoView.el);
- });
|