ember-data

ember data 1.0.x not saving hasMany relationship when bidirectional

廉价感情. 提交于 2019-12-10 20:29:31
问题 One of the hasMany relationships isn't POSTing back to the server. How are you supposed to model a bidirectional relationship? Here are the pertinent objects: Encompass.Selection = DS.Model.extend({ text: DS.attr('string'), submission: DS.belongsTo('submission', {inverse: 'selections'}), }); Encompass.Submission = DS.Model.extend({ shortAnswer: DS.attr('string'), selections: DS.hasMany('selection'), testing: DS.hasMany('folder'), workspaces: DS.hasMany('workspace'), }); and a controller

Ember.js REST Ajax Success and Error

匆匆过客 提交于 2019-12-10 20:18:29
问题 I'd like to know what the success and error do in the Ember.js RESTAdapter's ajax function. hash.success = function(json) { Ember.run(null, resolve, json); }; hash.error = function(jqXHR, textStatus, errorThrown) { Ember.run(null, reject, jqXHR); }; I know hash is the data sent through AJAX, but what role do success and error play? I assume they'd be run based on a successful or erroneous AJAX response, right? They're set before the AJAX is called, as callbacks? How do they work? 回答1: but

ember data computed property not working on nested association

烂漫一生 提交于 2019-12-10 19:57:42
问题 I have a simple datamodel: a Leg, has many Players, who have many Turns: App.Store = DS.Store.extend({ revision: 11, adapter: 'DS.FixtureAdapter' }); App.Leg = DS.Model.extend({ players: DS.hasMany('App.Player'), turnCount: function() { var i = 0; this.get('players').forEach(function(p) { i+= p.get('turns.length'); }); return i; }.property('players.@each.turns.length') }); App.Player = DS.Model.extend({ leg: DS.belongsTo('App.Leg'), turns: DS.hasMany('App.Turn') }); App.Turn = DS.Model.extend

Ember.js: Get id from currently active route

落爺英雄遲暮 提交于 2019-12-10 19:55:47
问题 Probably the most straight-forward question I've asked recently. Given a route set up like so: Social.Router.map(function() { this.resource('accounts', function(){ this.resource('account', { path: ':account_id'}); }); }); And a URL like so: /accounts/12 How would I get the account_id if I wanted to get the currently active account record? The end goal is that I'm doing this: acct = App.Account.find(12) When I'd rather do this acct = App.Account.find(account_id) UPDATE 1 Here's the

Ember Acceptance Test Failing in PhantomJS but Passing in Chrome

笑着哭i 提交于 2019-12-10 19:27:51
问题 I'm trying to write an acceptance test for my Ember app and I seem to be having some trouble when it comes to PhantomJS and the Ember test server. I'm running the following versions: Ember : v1.13.6 Ember Data : v1.13.7 PhantomJS is failing with the following error: Died on test #1 at http://localhost:7357/assets/test-support.js:2934 at http://localhost:7357/assets/test-support.js:6640 at http://localhost:7357/assets/test-loader.js:31 at http://localhost:7357/assets/test-loader.js:21 at http:

How to display error message in ember js 2.0

那年仲夏 提交于 2019-12-10 18:06:08
问题 I would like to display an error message when the server responses with record not found. The model in the route handler: model: function(userLoginToken) { var userLoginToken= this.store.createRecord('userLoginToken'); return userLoginToken; }, The action: actions: { sendOTP: function(userLoginToken) { var thisObject = this; var model=this.currentModel; this.store.findRecord('user-login-token', userLoginToken.get('mobileNumber')).then(function(response) { //thisObject.get('controller').set(

Ember-cli Fixture loading

梦想的初衷 提交于 2019-12-10 17:49:53
问题 I'm certain its something small and stupid I'm missing but can't seem to get my fixtures to load. Here is I've got... app/models/todos.js import DS from 'ember-data'; var Todo = DS.Model.extend({ title: DS.attr('string'), isCompleted: DS.attr('boolean') }); Todo.reopenClass({ FIXTURES: [ { id: "1", title: 'install ember-cli', isCompleted: true }, { id: "2", title: 'install additional dependencies', isCompleted: true }, { id: "3", title: 'develop amazing things', isCompleted: false } ]});

Cache a record when using Query Params in the call? Ember-data

夙愿已清 提交于 2019-12-10 17:48:21
问题 I have got this route retrieving 2 models: App.PanelRoute = Ember.Route.extend({ model: function(){ var topologymin = this.store.find('topologymin'); var metricmap = this.store.find('metricmap', { param1: 'something'}) return Ember.RSVP.hash({ topologymin: topologymin, metricmap: metricmap }); }); This makes 2 calls: http://localhost/topologymins http://localhost/metricmaps?param1=something If I go to another route and again to this one, it makes again the call with the params, not the other

Handling server side validation with Ember Data

风格不统一 提交于 2019-12-10 17:14:14
问题 I'm having trouble handling server side validations with Ember and Ember Data. When a validation error occurs, the API returns the code 422. Ember data then triggers the becameInvalid callback on the model. From here, I'm not sure what's the best way to handle the errors I'm getting, and how to make them bubble up to the view. App.Challenge = DS.Model.extend Ember.Validations, title: attr('string') summary: attr('string') # other attributes becameInvalid: (errors) -> # is it the place where I

ember data REST change JSON

笑着哭i 提交于 2019-12-10 16:38:55
问题 I am using ember-data 1.0.0-beta.4. On update it sends PUT request with following JSON {"property": { "name":"name", "age":"22" } } How can change my RESTAdapter to send following JSON instead of above { "name":"name", "age":"22" } Please help Thanks 回答1: create a custom serializer and override the serializeIntoHash hook, something like this should do it (I didn't test this). Read more about serializers here: https://github.com/emberjs/data/blob/master/TRANSITION.md App.PropertySerializer =