ember-data

Save nested models using Ember Data

喜夏-厌秋 提交于 2019-12-25 09:29:58
问题 I have two models in Ember: Collection export default DS.Model.extend({ name: DS.attr(), description: DS.attr(), items: DS.hasMany('collection-item') }); Collection Item export default DS.Model.extend({ date: DS.attr(), volume: DS.attr(), sequenceNumber: DS.attr() }); I want to save the collection items inside the 'items' attribute of the collection, like MongoDB: [{ "name": "First Collection", "description": "This is my first collection", "items": [ { "date": "2017-07-26", "volume": "1",

Can Ember-Data handle two models from one JSON payload?

≡放荡痞女 提交于 2019-12-25 06:58:45
问题 I have JSON coming from the server which looks like: data: { user: { address: { id: "id", city: "city", street: "street", ....... } name: "name", ...... } authentication-token: { token: "token", id: "id" } } The idea is to store this two models (user, authentication-token) in ember store under the same names. When I gat the above mentioned response from a server, model user is saved successfully, but model authentication-token does not get saved to the store at all. When I log the data (in

Delete Record in Emberjs

偶尔善良 提交于 2019-12-25 06:07:09
问题 I am struggling to follow ember 2.0's documentation for deleting records and then redirecting to a new url. When I try, I get the following error to the console: Error while processing route: pencils Attempted to handle event `pushedData` on <name-emberjs@model:pencil::ember523:null> while in state root.deleted.inFlight. Error: Attempted to handle event `pushedData` on <name-emberjs@model:pencil::ember523:null> while in state root.deleted.inFlight. My files follow. Routes: import Ember from

Ember.computed.sort doesn't seem to work

十年热恋 提交于 2019-12-25 05:30:37
问题 I have a template like so: {{#each rate in package.ratesSorted}} {{rate.year}} {{/each}} I want the rates to be sorted by ascending year, so I have: var Package = DS.Model.extend({ rates: DS.hasMany('rate'), ratesSorted: Ember.computed.sort('rates', (a, b) => { return a.get('year') > b.get('year'); }) }); Package.reopenClass({ FIXTURES: [ {id: 1, rates: [1, 3, 4]} ] }); And my rate Model looks like this: var Rate = DS.Model.extend({ year: DS.attr('number'), }); Rate.reopenClass({ FIXTURES: [

Ember, hasMany and belongsTo doesn't work

我的未来我决定 提交于 2019-12-25 05:05:23
问题 I tried a simple emberapp to display some userdata. My API returns me this json: { "roles":[ { "id":5, "name":"admin", "alias":"Administrator", "users":[ { "id":1, "username":"Evolutio", "email":"mail@evolutio.tld", "display_role":"Administrator" } ] }, { "id":2, "name":"user", "alias":"Benutzer", "users":[ ] }, { "id":1, "name":"banned", "alias":"Gesperrt", "users":[ ] }, { "id":3, "name":"mod", "alias":"Moderator", "users":[ ] }, { "id":4, "name":"support", "alias":"Supporter", "users":[ ]

edit template not displaying on edit route

这一生的挚爱 提交于 2019-12-25 04:55:09
问题 I would like to edit users. I am following this tutorial: http://coding.smashingmagazine.com/2013/11/07/an-in-depth-introduction-to-ember-js/ I have a button in user.hbs to edit the user: <button {{action "edit"}}>Edit</button> and below it is an {{outlet}} When click it I'm directed to /index.html#/users/4/edit but my user.edit.hbs template does not show up Here's userEditRoute.js : App.UserEditRoute = Ember.Route.extend({ model: function(){ return this.modelFor('user'); } }); And the

Mapping route to a explicit path does not work

江枫思渺然 提交于 2019-12-25 04:07:26
问题 I am defining a resource as explained here: App.Router.map(function () { this.resource('phones', { path: '/nodes/extensions/phones' }, function () { this.route('new'); }); But this is not working. Finding the phones performs a request to /phones instead of using the configured value /nodes/extensions/phones . What am I doing wrong? 回答1: The path here is the path used in the browser address bar, e.g. a user would access "http://yoursite.com/#/nodes/extensions/phones" to see this page on your

Observe change on any attribute of an Ember Data

[亡魂溺海] 提交于 2019-12-25 03:34:07
问题 Is this possible? Something like .observes('_data') , but not. The use case is, I have a Decays mixin that has some CPs that say how long its been since a model has been updated. I'd like these CPs to be able to update if any of the model's attrs have changed. isDirty also won't work, since my use case uses store.push to update the model. 回答1: I don't think there's a built-in way to do it, but it wouldn't be very difficult to make one. Just create a base class for all of your models and

Ember Authentication paradigm

北慕城南 提交于 2019-12-25 02:08:54
问题 Let's consider a trivial use case: User edits his profile + we have a RESTful server. This means we have to send a token to the server and at the same time the new information about the editing. First, the server has to decode the token, and later to CRUD the DB. We want also to send back to the client a new json model about the new user profile. BUT the token is really a huge one, so we must send it with a POST request. We can send the additional information as a query string at the same

Serialize JSON into Ember-Data (two different models in payload)

蹲街弑〆低调 提交于 2019-12-25 02:08:21
问题 I have JSON coming from the server which looks like: data: { user: { address: { id: "id", city: "city", street: "street", ....... } name: "name", ...... } authentication: { token: "token", id: "id" } } In Ember I have a model auth which should represent the authentication model that I get from the server. Since I have different names for same model on the server and in the Ember store, I wrote a serializer with one method typeForRoot(root) where I just map server authentication to Ember auth