ember-data

ember data serializer data mapping

帅比萌擦擦* 提交于 2019-12-19 04:08:11
问题 I'm using ember & ember-data to try and consume a json feed from the server. Here is my code: App = Ember.Application.create(); DS.RESTAdapter.configure( "plurals", { category: 'categories' } ); App.Store = DS.Store.extend({ revision: 12, adapter: DS.RESTAdapter.create({ url: 'app' }) }); App.Router.map(function(){ this.resource('categories'); }); App.CategoriesRoute = Ember.Route.extend({ model: function() { return App.Category.find(); } }); var attr = DS.attr; App.Category = DS.Model.extend

How do you access RESTAdapter's host and namespace inside a route or controller?

拈花ヽ惹草 提交于 2019-12-18 19:06:00
问题 I have a few custom AJAX requests that I use inside of some controllers and routes, for example: var loginRoute = Ember.Route.extend({ actions: { submitLogin: function(user, pass) { var data = { username: user, password: pass }; Ember.$.post('http://192.168.2.10/api/v1/login', data).then(); } } }); This works fine, but while developing I may have a different IP (e.g. changing routers) and I'd like to be able to access the URL(host + namespace) I defined when I extended the RESTAdapter so that

Update view when pushing models to the store

爱⌒轻易说出口 提交于 2019-12-18 16:51:23
问题 I have quite a complex page in my application with lots of different models being shown. I live-update several of these models through a /updates REST call. I pass a last_request_timestamp parameter and it returns the models that were created or modified since the last call. I add the models to the store by using store.push(model, model_json) . However, the templates are not updated after the models have been pushed. How can I ensure that there is a binding between the models in the store and

Adding item to filtered result from ember-data

时光总嘲笑我的痴心妄想 提交于 2019-12-18 15:57:07
问题 I have a DS.Store which uses the DS.RESTAdapter and a ChatMessage object defined as such: App.ChatMessage = DS.Model.extend({ contents: DS.attr('string'), roomId: DS.attr('string') }); Note that a chat message exists in a room (not shown for simplicity), so in my chat messages controller (which extends Ember.ArrayController ) I only want to load messages for the room the user is currently in: loadMessages: function(){ var room_id = App.getPath("current_room.id"); this.set("content", App.store

How to cache query result in ember data

﹥>﹥吖頭↗ 提交于 2019-12-18 13:53:08
问题 I want to cache the result of a query in ember-data. ( findQuery ) To make it clear: I don't want to cache the entire models; just what models are the result of the query. Where is the right place for this? I was thinking about implementing this in the adapter and cache the result of the AJAX call, but I don't think this is a good solution since I don't wanna override the loaded and maybe newer and/or modified model data. I don't thinks its possible to just return a list of ID's, and to

Filter child-records (hasMany association) with Ember.js

别等时光非礼了梦想. 提交于 2019-12-18 13:49:08
问题 Is there any possibility to filter the hasMany records from a model record? I want to get the active projects, grouped by the customer. Customer model Docket.Customer = DS.Model.extend({ name: DS.attr('string'), initial: DS.attr('string'), description: DS.attr('string'), number: DS.attr('string'), archived: DS.attr('boolean'), projects: DS.hasMany('project',{ async: true }) }); Project model Docket.Project = DS.Model.extend({ name: DS.attr('string'), description: DS.attr('string'), number: DS

Filter child-records (hasMany association) with Ember.js

你离开我真会死。 提交于 2019-12-18 13:49:00
问题 Is there any possibility to filter the hasMany records from a model record? I want to get the active projects, grouped by the customer. Customer model Docket.Customer = DS.Model.extend({ name: DS.attr('string'), initial: DS.attr('string'), description: DS.attr('string'), number: DS.attr('string'), archived: DS.attr('boolean'), projects: DS.hasMany('project',{ async: true }) }); Project model Docket.Project = DS.Model.extend({ name: DS.attr('string'), description: DS.attr('string'), number: DS

How do I setup the api-stub in an ember-cli app?

半世苍凉 提交于 2019-12-18 12:32:27
问题 I’m setting up a basic app using ember-cli and am running into trouble with the api-stub with ember-data. I've referenced the api-stub README and have referenced the ember guides, but can't figure out what I'm missing. I’m a bit of a noob, so forgive any obvious oversights on my part. Here's my setup... /api-stub/routes.js server.get('/listings', function(req, res) { var listing = { "listing": [{ "id": 1, "title": "Sunny 1-bedroom", "unit_type": "1br / 1ba", "description": "Roomy 1-bedroom

How to return a promise composed of nested models in EmberJS with EmberData?

不羁岁月 提交于 2019-12-18 12:30:15
问题 Enviroment # Ember : 1.4.0 # Ember Data : 1.0.0-beta.7+canary.b45e23ba Model I have simplified my use case to make the question easier to understand and anwser. Let's assume we have 3 models: Country , Region and Area : Country: - id: DS.attr('number') - name: DS.attr('string') - regions: DS.hasMany('region') Region: - id: DS.attr('number') - name: DS.attr('string') - country: DS.belongsTo('country') - areas: DS.hasMany('area') Area: - id: DS.attr('number') - name: DS.attr('string') - region:

How to (De)serialize field from object based on annotation using Jackson?

喜欢而已 提交于 2019-12-18 12:28:28
问题 I need to configure Jackson in a specific way which I'll describe below. Requirements Annotated fields are serialized with only their id: If the field is a normal object, serialize its id If the field is a collection of objects, serialize an array of id Annotated fields get their property names serialized differently: If the field is a normal object, add "_id" suffix to property name If the field is a collection of objects, add "_ids" suffix to property name For the annotation I was thinking