ember-data

Get Ember-Data REST response value

非 Y 不嫁゛ 提交于 2020-01-05 07:47:13
问题 Ember: 1.0.0-rc.6 Ember-Data: e999edb (2013-07-06 06:03:59 -0700) I make a REST call (POST) to login a user. Server response is ok. I need the ID from the server, but i only got the ID with "setTimeout". I think this is not the right way. What is my mistake? Within Controller i call: var login = App.Login.createRecord(this.getProperties("email", "password")); login.on("didCreate", function(record) { console.log(record.get("id")); // ID is null console.log(record.get("email")); }); setTimeout

Ember ActiveModelAdapter customization

北战南征 提交于 2020-01-05 06:52:31
问题 My Ember application interacts with an API (through a DS.ActiveModelAdapter adapter) which respond to GET "/api/v1/users?username=mcclure.rocio" with a JSON like: { "user": { "id": 5, "name": "Rocio McClure", "username": "mcclure.rocio", "email": "rocio.mcclure@yahoo.com" } } My router is: Router.map(function() { this.route("login"); this.route("user", {path: "user/:username"}, function() { this.route("profile"); }); }); So I have route like http://localhost:4200/user/mcclure.rocio which is

Ember: unsaved models in dynamic URLs

五迷三道 提交于 2020-01-05 04:42:29
问题 I'm currently using the FixtureAdapter in my Ember app, but when I switch to the RESTAdapter, my URLs no longer work. The app is a scorekeeping type thing, and I want users to be able to log all the scores without having to be connected to the Web. After the game is finished they can optionally save all the data to the server. Now, when Ember wants to route to say, matches/:match_id, the ID isn't there because I didn't commit anything to the server/store, so my models don't yet have an ID and

Is there any way to create a batch of multiple records with a single POST request in Ember Data?

点点圈 提交于 2020-01-04 13:41:13
问题 var batch = [someRecord, someRecord, someRecord...] batch.invoke('save'); If I have an array of 50 newly created records and then invoke save on that array, then Ember Data will make 50 POST requests. I would rather bulk them into a single request and handle that on the API for performance. Is there any way to do this? Right now it appears I will have to implement this manually with ajax. But if there is a better way, please share. 回答1: There used to be a bulkCommit feature in ember-data on

#ember-power-select, How to set a preselected value in ember-power-select custom-search action

左心房为你撑大大i 提交于 2020-01-04 08:26:51
问题 There must be a value set in "selected" attribute before typing in search parameter".Can anyone help me to sort this out ? #ember-power-select It is working with normal action-handling by setting a value for "destination" in js and assigning "destination" to "selected". Have a look at here for such examples http://www.ember-power-select.com/docs/action-handling. But can't assign a value for custom-serach-action http://www.ember-power-select.com/docs/custom-search-action. My Code: Models:

peekRecord() is not working but peekAll() is working

牧云@^-^@ 提交于 2020-01-04 05:29:09
问题 My backend always responds with all available data and it took a considerably amount of time. So I'm reloading store periodically and I plan to use peekAll() and peekRecord(). My code is: model: function() { return Ember.RSVP.hash({ 'clusters': this.store.peekAll('cluster'), 'single': this.store.peekRecord('cluster', 'cluster::My') }); When code is executed, at first I can see that both of these items do not contain content. After few seconds data are loaded to store and I can see content

Polymorphic relationship with mixin

荒凉一梦 提交于 2020-01-04 04:45:10
问题 When using the hasMany and belongsTo relationships in Ember-Data, does it have to specify a class, or can I specify a mixin? For instance, I have an Attachement model that I want to link to some other models. Specifically, I want to assign Attachement s to Project s and Components . Can I use a mixin on Projects and Component and use that mixin as the inverse like below? App.Attachment = DS.Model.extend({ attachedTo: DS.belongsTo('canHaveAttachments', { inverse: 'attachments'}); }); App

Ember Data - rollback if navigating away from a form

末鹿安然 提交于 2020-01-03 18:31:44
问题 My application has new / edit forms for a set of entities read from a backend. When I open such a form, and fill out / edit some fields, then navigate away, the records appear changed in the entity lists, even though I did not commit those changes. Reloading the app (which reloads the data from the backend) fixes the issue, but is not an option. I've tried doing some transaction rollbacks in the form view's willDestroyElement, but this seems fundamentally wrong since it gets called even after

EmberJS: The best way to reload controller's model based on another property?

风流意气都作罢 提交于 2020-01-03 08:06:30
问题 What is the best way to reload model for a current controller based on another property? For example: I have a post controller. Author can have only one post. I want to reload post creating form if currentAuthor property changes. I've tried that way: App.PostEditController = Ember.ObjectController.extend modelReloadNeeded: Ember.observer((obj, keyName) -> postId = @get('currentAuthor').get('post_id') if postId? @set('model', @store.find('post', postId)) , 'currentAuthor.post_id' ) It reloads

emberjs and ember-data -creating record via form submission returns undefined

 ̄綄美尐妖づ 提交于 2020-01-03 03:12:45
问题 I have this jsfiddle . Everything works excepting that i can't create a new comment by submitting the comment's form. when i submit a form the console shows undefined . What I hope to achive is to grab an existing post and then create a comment that belongs to that post. So this the flow of things, a user will click on post then click a specific post title to display it and then click on add comment to comment on that post. It is important to note that at the moment, clicking on add comment