ember-data

How to create a custom Serializer for Ember data

假如想象 提交于 2019-12-18 12:00:56
问题 I have an API that returns JSON that is not properly formatted for Ember's consumption. Instead of this (what ember is expecting): { events: [ { id: 1, title: "Event 1", description: "Learn Ember" }, { id: 2, title: "Event 2", description: "Learn Ember 2" } ]} I get: { events: [ { event: { id: 1, "Event 1", description: "Learn Ember" }}, { event: { id: 2, "Event 2", description: "Learn Ember 2" }} ]} So if I understood correctly, I need to create a custom Serializer to modify the JSON. var

How to create a custom Serializer for Ember data

拈花ヽ惹草 提交于 2019-12-18 12:00:02
问题 I have an API that returns JSON that is not properly formatted for Ember's consumption. Instead of this (what ember is expecting): { events: [ { id: 1, title: "Event 1", description: "Learn Ember" }, { id: 2, title: "Event 2", description: "Learn Ember 2" } ]} I get: { events: [ { event: { id: 1, "Event 1", description: "Learn Ember" }}, { event: { id: 2, "Event 2", description: "Learn Ember 2" }} ]} So if I understood correctly, I need to create a custom Serializer to modify the JSON. var

Ember async computed property returns undefined

久未见 提交于 2019-12-18 09:12:25
问题 I am attempting to set a property to the value of a model's async, hasMany relationship. But I'm not able to return any value within the then function. App.Athlete = DS.Model.extend({ name: DS.attr('string'), age: DS.attr('number'), splits: DS.hasMany('split', {async: true}), times: DS.hasMany('time', {async: true}), }); App.Time = DS.Model.extend({ athlete: DS.belongsTo('athlete', {async:true}), race: DS.belongsTo('race', {async: true}), time: DS.attr('string'), }); App.Split = DS.Model

Ember template not updating from arraycontroller

末鹿安然 提交于 2019-12-18 05:25:26
问题 In my app, a user can enter a description of a friend or upvote a description that is already present. Both methods (createDescription and upvoteDescription) persist in the database. upvoteDescription changes the DOM, but createDescription does not. It may be because I'm passing a parameter in the model, but I can't get around that -- the api needs it. //descriptions route App.DescriptionsRoute = Ember.Route.extend({ ... model: function () { var store = this.get('store'), friend = this

Transform JSON to an appropriate format for RESTAdapter EmberJS

旧街凉风 提交于 2019-12-18 05:04:09
问题 I receive a JSON from our API that has the following format [ { "id": 45, "name": "Pasta", "_order": 0, "is_hidden": null, "is_list": false }, { "id": 46, "name": "Salads", "_order": 1, "is_hidden": null, "is_list": false }, { "id": 47, "name": "Dessert", "_order": 2, "is_hidden": null, "is_list": false } ]; I see that it has invalid format for standard RESTAdapter and I need to put the name of the model first. In my example it should probably be like: { "category": [ { "id": 45, "name":

Using primary keys with Ember Data

随声附和 提交于 2019-12-17 22:42:10
问题 I've been struggling for the past few days with primary keys and the last version of Ember Data. I first read how to do it on the Breaking Changes file on GitHub, but it's apparently outdated. I tried several other ways (with the help of Peter Wagenet on IRC), but none of them seem to work. I would like to make slug my primary key on my model, and also since I'm working with MongoDB, I would like to use _id instead of id . Has anyone figured out how to do this? My underlying problem is that

Accessing controllers from other controllers

别等时光非礼了梦想. 提交于 2019-12-17 15:56:24
问题 I am building a project management app using ember.js-pre3 ember-data revision 11. How do I initialize a couple of controllers and make them available globally. For example I have a currentUser controller and usersController that I need access to in every state. I used to have the following code in the Ember.ready function but It no longer works. I guess the way I was doing it was intended for debugging. https://github.com/emberjs/ember.js/issues/1646 Old Way: window.Fp = Ember.Application

Ember data multi level hierarchy with embedded always

ε祈祈猫儿з 提交于 2019-12-17 13:40:11
问题 I am able to use embedded always for one level but I am unable to use it for two level deep model. Need an urgent help App.Post = DS.Model.extend( title: DS.attr("string") comment: DS.belongsTo("App.Comment") ) App.Comment = DS.Model.extend( text: DS.attr("string") ferment: DS.belongsTo("App.Ferment") ) App.Ferment = DS.Model.extend( fermenter: DS.attr("string") ) App.Adapter.map App.Post, 'comment': embedded: "always" App.Adapter.map App.Comment, ferment : embedded: "always" # --------------

Ember Data model's errors property (DS.Errors) not populating

喜夏-厌秋 提交于 2019-12-17 09:54:02
问题 I'm using Ember Data and I can't seem to get the model's 'errors' property to populate with the error messages from my REST API. I'm pretty much following the example at this guide: http://emberjs.com/api/data/classes/DS.Errors.html My app looks like this: window.App = Ember.Application.create(); App.User = DS.Model.extend({ username: DS.attr('string'), email: DS.attr('string') }); App.ApplicationRoute = Ember.Route.extend({ model: function () { return this.store.createRecord('user', {

ember.js model data is not being output by the collectionView

╄→гoц情女王★ 提交于 2019-12-14 04:21:39
问题 I am at sea, and would be grateful for any help, with the latest version of Ember. Using the todo example, i've tried to include routes and DS models in the following adapted http://jsfiddle.net/5HMzu/3/ When I use a #each controller in the handlebar template, output is as expected; replacing that with a CollectionView and trying to tie that to the data source, nothing is being output. The inserted code: App.PersonCollectionView = Ember.CollectionView.extend({ itemViewClass: "App