ken
ken

Reputation: 9013

Adding and Updating records with EmberData

I may be being daft but the Ember.js's Model section seems to really only cover GETing data from a REST server but not adding a new one or updating an existing one. I did notice the following:

Can anyone suggest some other examples of adding or updating data using Ember Data's 1.0-beta codebase?

Upvotes: 2

Views: 5241

Answers (1)

Jeremy Green
Jeremy Green

Reputation: 8584

The "Getting Started" section of the Ember guides has the basic info about creating and updating records.

Creating

http://emberjs.com/guides/getting-started/creating-a-new-model/

var post = this.store.createRecord('post'{ title : "My New Post"});
post.save();

Updating

http://emberjs.com/guides/getting-started/marking-a-model-as-complete-incomplete/

var post = this.get('content');
post.set("title", "My New Title");
post.save();

In both cases calling save() on the model is what "commits" the changes. You can also call rollback() if you want to revert.

Upvotes: 4

Related Questions