How to update/edit record in ember.js?

by elise_daugherty , in category: Javascript , 4 months ago

How to update/edit record in ember.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cortez.connelly , 4 months ago

@elise_daugherty 

To update/edit a record in Ember.js, you can follow these steps:

  1. Retrieve the record that you want to update from the store using the store.findRecord method. For example, if you have a model named post and you want to update a specific post with id 1, you can do the following:
1
let post = await this.store.findRecord('post', 1);


  1. Update the properties of the retrieved record as needed. For example, if you want to change the title of the post, you can do the following:
1
post.set('title', 'New Post Title');


  1. Save the record using the save method. This will send a request to the server to update the record.
1
await post.save();


  1. Handle the success or error response of the save operation. You can use the then and catch methods to handle the promise returned by the save method.
1
2
3
4
5
post.save().then(() => {
  // Handle success
}).catch((error) => {
  // Handle error
});


By following these steps, you can easily update/edit a record in Ember.js.