ember.js

Mocking HTTP requests in ember-qunit

删除回忆录丶 提交于 2020-01-24 22:05:26
问题 In an ember-cli app, testing is done using ember-qunit. I would like to mock HTTP requests, but have not been able to find a recommended way of doing this in the documentation. I have found this thread which discusses this, but it appears to be out of date (for ember-cli anyway). How do you mock HTTP requests? 回答1: This is how I mock HTTP requests. One improvement could be done by encapsulating mockjax with helper like: function stubEndpointForHttpRequest(url, json) { $.mockjax({ url: url,

Ember.js how to remove object from array controller without ember data

梦想的初衷 提交于 2020-01-24 18:36:46
问题 I am trying to update the arraycontroller model after deleting a record using jquery ajax.I can add a new object using self.pushObject(data) , but i cannot remove the object using self.removeObject(data) . can someone please help. ("data" is the object that i removed, the server sends it back after removing it in server.) removeTodo: function(id) { var page_id = id; self = this; Ember.$.ajax({ url: url+id, type: "DELETE" }).then(function(data) { self.removeObject(data); }); } 回答1: data might

Catch 404 error when using store.findQuery

六眼飞鱼酱① 提交于 2020-01-24 17:00:08
问题 I'm using Embers findQuery method and wonder how to catch 404 errors when there are no results? this.store.findQuery('customer', { hasProjects: true, getArchivedProjects: archived }).then(function(customers) { }); If the query is empty, the code inside this then function doesn't get fired, so I can't even check the type of customers . Example: this.store.findQuery('customer', { hasProjects: true, getArchivedProjects: archived }).then(function(customers) { console.log('foo') }); If the query

assertion failed: An outlet (menu) was specified but this view will render at the root level

耗尽温柔 提交于 2020-01-24 14:15:31
问题 I have this weird assertion error when I was rendering an extra outlet on the root level of my application. This is the code I use: <div id="app"> <nav>{{outlet "menu"}}</nav> <div class="content">{{outlet}}</div> </div> I have a template called menu . This is my App.ApplicationRout app.ApplicationRoute = Ember.Route.extend({ renderTemplate: function() { this.render(); this.render("menu", { outlet: "menu" }); } }); But it is throwing an error: assertion failed: An outlet (menu) was specified

Emberjs Testing a Component's action delegate

强颜欢笑 提交于 2020-01-24 01:07:21
问题 I'm trying to test a simple component that uses action delegation. I want to test that a certain action is sent to the actionDelegate of a component. I was thinking of using Sinon to check that the action was being sent, but I can't work out how to replicate the structure that Ember uses to send its actions to its delegates/targets. What structure would my sinon "spy delegate" object take in order for me to check that the component is delegating the event using "send" when the user clicks on

Ember fixtures not working

懵懂的女人 提交于 2020-01-23 18:38:09
问题 This is my code (using ember-cli): app.coffee `import Ember from 'ember'` `import Resolver from 'ember/resolver'` `import loadInitializers from 'ember/load-initializers'` Ember.MODEL_FACTORY_INJECTIONS = true App = Ember.Application.extend modulePrefix: 'dashboard' # TODO: loaded via config Resolver: Resolver loadInitializers App, 'dashboard' `export default App` adapters/application.coffee `import DS from 'ember-data'` ApplicationAdapter = DS.FixtureAdapter.extend() `export default

what is the right emberjs way to switch between various filtering options?

妖精的绣舞 提交于 2020-01-23 09:21:44
问题 I've an individualStore (extends from Em.ArrayController), whose task is to keep an array of individual objects. There are several APIs that my application calls, and they return individual objects which are sent to the store. Think about it as the database of cached individual records in my application. App.individualStore = App.ArrayController.create({ allIndividuals: function () { return this.get('content').sort(function (a, b) { return (b.votes_count - a.votes_count); }); }.property('

Ember Data, how to use registerTransform

╄→гoц情女王★ 提交于 2020-01-22 16:26:12
问题 I've been Googling for a while now, but haven't found any good solution. The root of the problem is that my records aren't being set to isDirty when using this method: DS.JSONTransforms.object = { deserialize: function(serialized) { return Ember.isNone(serialized) ? {} : serialized; }, serialize: function(deserialized) { return Ember.isNone(deserialized) ? {} : deserialized; } } From what I gather this is an old method that apparently still works, since it handles the JSON objects I'm

Ember Data, how to use registerTransform

岁酱吖の 提交于 2020-01-22 16:25:08
问题 I've been Googling for a while now, but haven't found any good solution. The root of the problem is that my records aren't being set to isDirty when using this method: DS.JSONTransforms.object = { deserialize: function(serialized) { return Ember.isNone(serialized) ? {} : serialized; }, serialize: function(deserialized) { return Ember.isNone(deserialized) ? {} : deserialized; } } From what I gather this is an old method that apparently still works, since it handles the JSON objects I'm

Different Ember Routes or Displaying Two Complex Views in their own context

社会主义新天地 提交于 2020-01-22 16:03:20
问题 I have an app with different related concerns. I have a list of items on the left that affect some of the items on the right (think Github Issues), but here's a mockup All fine, I click Item One and something happens on the right. However, the list on the left has its own routing requirements, it's a resource of items with nested routes. For example when we click on Create New Item we display a new form inline (see bottom left corner) When I do that it, even if it's on a different outlet, it