ember-data

Listening when new records are added to the store via a computer property

这一生的挚爱 提交于 2019-12-13 01:19:51
问题 I am pushing records into my store using websockets. I am displaying items on the screen via a handlebars template {{#each item in items}} <div>{{item.name}}</div> {{/each}} In my controller I have the items collection items : function() { var items = this.store.find('items'); return items.filterBy({type : "NEW"}); }.property() Now, when new records are added to the store, I need to update the items automatically. items : function() { var items = this.store.find('items'); return items

Force a controller to always act as a proxy to a model in Ember

给你一囗甜甜゛ 提交于 2019-12-12 18:15:33
问题 I'm looping through a content of an ArrayController whose content is set to a RecordArray. Each record is DS.Model, say Client {{# each item in controller}} {{item.balance}} {{/each}} balance is a property of the Client model and a call to item.balance will fetch the property from the model directly. I want to apply some formatting to balance to display in a money format. The easy way to do this is to add a computed property, balanceMoney, to the Client object and do the formatting there: App

How do I save data to my Ember store if the POST response contains only an id?

时光总嘲笑我的痴心妄想 提交于 2019-12-12 17:26:23
问题 Ember data expects my server to return the full object after each successful POST . However, my API only returns a kind of meta-object that contains the id . When Ember receives this object, the existing data in the record gets deleted except for the id . So for example, when I do this: var asset = App.Asset.store.createRecord('asset',{name: 'foo.ai', paths: ['/path/foo.ai', '/another/path/foo.ai'], type: 'ai', hash: '1234567890123456789012345678901234567890', datecreated: 'Sun, 12 Jan 2014

How to handle a 400 error with Ember Data (2.4.0-canary)

巧了我就是萌 提交于 2019-12-12 15:42:33
问题 I can't figure out if my problem has to do with my query or my response or something else. In my route I'm using a queryRecord : model(params) { return this.store.queryRecord('invitation', { 'invitation_token' : params.invitationToken }); }, I'm properly receiving on the server side but I'm testing the case where the invitation token no longer exists. Therefore, the server is returning a 400 with a json payload which has an explanation of the error. {"error":"Error finding invitation"} But

Ember.js - How to handle error with DS.store.findRecord() method

你。 提交于 2019-12-12 14:44:41
问题 I am using following simple code to retrieve user from server. var someUser = this.store.findRecord('user', 0); I am using this for retrieving the user. if user is not found on 0 id, server returns 404. and error as per json api. but how do i know about error on client side about it ? 回答1: Taken from Ember guides: Use store.findRecord() to retrieve a record by its type and ID. This will return a promise that fulfills with the requested record. Since the return value is a promise, you can use

How to delete all data from Ember Data store? [duplicate]

自古美人都是妖i 提交于 2019-12-12 13:58:50
问题 This question already has answers here : Ember.js Data how to clear datastore (7 answers) Closed 6 years ago . In the Ember.js application I'm working on, that uses Ember-data, once the user gets to a point on the screen, I want to delete all state stored in the ember-data Store associated with the application, and start with a clean slate that can start pulling data from the server. Anyone know how to do it? 回答1: I don't think there is an easy way. The only way ATM is loop over all your DS

serialize date attributes

巧了我就是萌 提交于 2019-12-12 10:35:25
问题 I am using active_model_serializers and ember.js. One of my models has a date attribute. In rails date attributes are serialized in the format of "YYYY-MM-DD". The problem; when ember-data de-serializes the date using the javascript Date constructor it assumes an "incorrect" timezone. *Incorrect is not the best word but it is incorrect because I want it to default to the current timezone. DS.Model date attribute parses date (YYYY-MM-DD) incorrectly I am thinking the active_model_serializer

Handling Validation Errors in Ember.js

萝らか妹 提交于 2019-12-12 09:42:02
问题 I have a rails app serving json to an ember frontend. I am trying to display validation errors from on a form on the client. Rails is returning this json: {"errors":{"hometown":["is too long (maximum is 64 characters)"]}} In my handlebars template for the current route I am attempting to iterate through the errors but I don't get any output for the errors section: <div class="form-group"> <label>Hometown</label> {{#each errors.hometown}} {{this}} {{/each}} {{input type="text" class="form

Ember data - dynamic segments and query params together?

佐手、 提交于 2019-12-12 09:02:53
问题 Using Ember 1.8.0 and Ember Data 1.0.0-beta.11, Ember store's findQuery() function doesn't seem able to handle dynamic segments, or at least I'm not able to find it in documentation anywhere. For example, given the following routes MyApp.Router.map -> @resource 'users', -> @resource 'user' path: 'users/:user_id' , -> I know that store.findQuery('user', {foo: 'bar'}) sends a GET request to myapp.com/users?foo=bar and also, store.find('user', 1) sends a GET request to myapp.com/users/1 but now

Accordion wizard with multiple steps in ember

雨燕双飞 提交于 2019-12-12 08:59:49
问题 I am using ember to built a "wizard accordion" . Basically what I want is: an accordion which is always shown the accordion contains all the steps one step is active but it is also possibly to change the header of previous steps each step has its own model (e.g. Selecting from countries in first step, selecting from products in second) it should be possible to jump back and force between steps out of all the selections a central model is built which is sent to the server after the final step