Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Latest commit

 

History

History
63 lines (48 loc) · 975 Bytes

plug-in-a-service.md

File metadata and controls

63 lines (48 loc) · 975 Bytes

Model - plug in a service

Note: Only Properties will get transferred to the server. Observables and other values will not.

Creating a record

var Profile = App.Model({
  options: {
    idAttr: 'id',

    create: {
      url: 'profile/create'
    }
  }
});

var profile = Profile({
    username: 'user1'
});

profile.sync();

Updating a record

var Profile = App.Model({
  options: {
    idAttr: 'id',

    update: {
      url: 'person/update'
    }
  },

  changePassword: function (newPassword) {
    this.password(newPassword);
    this.sync();
  }
});

Deleting a record

var Person = App.Model({
  options: {
    idAttr: 'id',

    destroy: {
      url: 'person/destroy'
    }
  },

  deleteItem: function () {
    this.destroy();
    this.sync();
  }
});

You could find how to populate collection of objects from a service here