ember.js

Ember-Data: How do “mappings” work

本小妞迷上赌 提交于 2020-01-09 09:10:15
问题 I'm currently trying to put something together with ember + emberdata + router + asp.net web api. Most of it seem to work, however I stuck in an error message I get when ember-data tries to findAll through the adapter for my models. In my backend I have a model like this (C#): public class Genre { [Key] public int Id { get; set; } [Required] [StringLength(50, MinimumLength=3)] public string Name { get; set; } } Which in my app I represent it like this using ember-data: App.Genre = DS.Model

Ember-Data: How do “mappings” work

妖精的绣舞 提交于 2020-01-09 09:10:12
问题 I'm currently trying to put something together with ember + emberdata + router + asp.net web api. Most of it seem to work, however I stuck in an error message I get when ember-data tries to findAll through the adapter for my models. In my backend I have a model like this (C#): public class Genre { [Key] public int Id { get; set; } [Required] [StringLength(50, MinimumLength=3)] public string Name { get; set; } } Which in my app I represent it like this using ember-data: App.Genre = DS.Model

Ember data saving a relationship

天大地大妈咪最大 提交于 2020-01-09 03:19:12
问题 I'm having difficult saving a one-to-many relationship in ember data. I have a relationship like this: App.ParameterSet = DS.Model name: DS.attr("string") regions: DS.hasMany("App.Region") App.Region = DS.Model name: DS.attr("string") If I were to do something like this: parameterSet = App.ParameterSet.find(5) @transaction = @get("store").transaction() @transaction.add(parameterSet) region1 = App.Region.find(10) region2 = App.Region.find(11) parameterSet.set("name", "foo") parameterSet.get(

ember-cli typeahead causes errors inside ember.js

放肆的年华 提交于 2020-01-07 07:09:13
问题 installed type-ahead component from bower. and try to use {{type-ahead data=companies name="name" selection=selectedCompany}} component in action. it causes errors inside ember.js (_changeSingle and afterFunc functions) "Uncaught TypeError: Cannot read property 'selectedIndex' of undefined " Uncaught TypeError: Cannot read property 'nextSibling' of null is it for versions? 回答1: Here is my own typeahead ember component: Component App.XTypeaheadComponent = Ember.Component.extend({

Why are routes and controllers classes and not objects?

匆匆过客 提交于 2020-01-07 05:51:07
问题 Both routes and controllers are singleton classes, so why not just do Ember.Route.create() or Ember.Controller.create() ? 回答1: This is only a guess, but I would imagine because this way is more versatile. Yes, controllers and routes and singletons now , but they might not always be. If Ember decides tomorrow that controllers no longer need to be singletons, you don't have to change the way you've declared your controllers. (I think there might even be a way in the container to make it so your

Serialize ids when saving emberjs model

放肆的年华 提交于 2020-01-07 05:28:06
问题 I have an emberjs application backed by a nodejs server and mongodb . Currently my database is sending documents with an '_id' field. I have the followign code to force Ember to treat '_id' as the primary key : App.ApplicationSerializer = DS.RESTSerializer.extend({ primaryKey: '_id' }); On the other hand i have two models related by a 'hasMany' relationship as such: App.Player = DS.Model.extend({ name: DS.attr('string'), thumbLink: DS.attr('string'), activeGame: DS.belongsTo('game', { async:

EmberJS: refreshing a data model does not update associated computed properties

这一生的挚爱 提交于 2020-01-07 05:28:05
问题 Let's say there is a route with capabilities to update it's data when requested by the user (assume the backend returns different data for the same call, maybe it's stock data, or just random numbers). export default Ember.Route.extend({ model() { return this.get('store').findAll('foo'); }, actions: { invalidateModel() { this.refresh(); } } }); Now, a component consuming this model directly will update its view as expected. Model: {{#each model as |m|}}{{m.bar}}{{/each}} <button {{action

Display JSON Api conform errors

北战南征 提交于 2020-01-07 05:25:25
问题 I receive JSON Api conform errors from the backend: { "errors": [ { "status": "400", "source": { "pointer": "/data/attributes/description" }, "detail": "This field may not be null." }, { "status": "400", "source": { "pointer": "/data/attributes/due-date" }, "detail": "This field may not be null." }, { "status": "400", "source": { "pointer": "/data/attributes/extra-comments" }, "detail": "This field may not be null." }, { "status": "400", "source": { "pointer": "/data/attributes/name" },

POST request to API from Ember often fails with 'The adapter operation was aborted Error'

无人久伴 提交于 2020-01-07 04:14:08
问题 I'm writing an Ember tutorial that I'd like to run on top of a very simple API I've created in Flask. PUT, DELETE, and GET requests made from ember-data behave as expected. The POST request throws an error and does not complete. The POST Ajax request is canceled before it's sent. This behavior is intermittent. If I set a breakpoint and follow it through the Ember internals then by the time I'm done, the request will often succeed. When running the API locally the error is thrown but the new

highlight current item in navbar using ember.js

久未见 提交于 2020-01-07 02:38:53
问题 I am trying to highlight the current item in my navigation bar. This is my router: App.Router = Em.Router.extend({ enableLogging: true, location: 'hash', root: Em.Route.extend({ // EVENTS gotoList: Ember.Route.transitionTo('list'), gotoAbout: Ember.Route.transitionTo('about'), // STATES list: Em.Route.extend({ route: '/list', connectOutlets: function(router, context) { router.get('applicationController').connectOutlet('list'); }, enter: function(router) { $('.active').removeClass('active'); $