Created
November 6, 2015 10:48
-
-
Save nightire/b52ef7dfecbd6a08c86d to your computer and use it in GitHub Desktop.
Unable to use mockjax with ember data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
init() { | |
this._super(...arguments) | |
$.mockjax({ | |
url: '/parents/1', | |
responseText: { | |
data: { | |
type: 'parent', | |
id: '1', | |
relationships: { | |
child: { | |
data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'].map(child => ({ type: 'child', id: child })) | |
} | |
} | |
} | |
} | |
}); | |
$.mockjax({ | |
url: /^\/children\/(\d+)$/i, | |
urlParams: ["childId"], | |
response: function(settings) { | |
this.responseText = { | |
data: { | |
type: 'child', | |
id: settings.urlParams.childId, | |
attributes: { | |
parent: '1' | |
} | |
} | |
} | |
} | |
}); | |
}, | |
model() { | |
return this.store.find('parent', '1') | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
parent: DS.belongsTo('parent', { async: true }) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
children: DS.hasMany('child', { async: true }), | |
oddChildren: Ember.computed('[email protected]', function() { | |
return DS.PromiseArray.create({ | |
promise: this.get('children').then(function(children) { | |
return children.filter(function(child) { | |
return child.get('id') % 2 !== 0 | |
}); | |
}) | |
}); | |
}) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.4.16", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.1.0", | |
"ember-data": "2.1.0", | |
"ember-template-compiler": "2.1.0", | |
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.5.3/jquery.mockjax.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment