Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible in Ember to display a message when there is no model?
    primarykey
    data
    text
    <p>Apologies if this question is very elementary, but I am a first time Ember user and I am working on an app. The app loads a list of visited cities, all of which are links to display recommendations. I have no problems loading the list of cities and linking to them. The problem is clicking on a link which does not have recommendations. I want to be able to detect that there are no recommendations for the city and display a message to the user. I can't quite figure out how to do that. Here is my current setup:</p> <p>Application and Store:</p> <pre><code>window.TR = Ember.Application.create({ LOG_TRANSITIONS: true, LOG_VIEW_LOOKUPS: true, LOG_ACTIVE_GENERATION: true }); Ember.LOG_BINDINGS = true; TR.Store = DS.Store.extend({ revision: 12, adapter: 'DS.FixtureAdapter' }); </code></pre> <p>Models and fixtures:</p> <pre><code>TR.location = DS.Model.extend({ city: DS.attr('string'), state: DS.attr('string'), country: DS.attr('string'), visited: DS.attr('boolean'), recos: DS.hasMany('TR.recos'), locationName: function () { var ret = this.get('city'); if (this.get('state') != null) ret += ', ' + this.get('state'); return ret + ', ' + this.get('country'); } .property('city', 'state', 'country') }); TR.recos = DS.Model.extend({ type: DS.attr('string'), name: DS.attr('string'), address1: DS.attr('string'), address2: DS.attr('string'), city: DS.attr('string'), state: DS.attr('string'), country: DS.attr('string'), postalCode: DS.attr('string'), phone: DS.attr('string'), website: DS.attr('string'), location: DS.belongsTo('TR.location') }); TR.location.FIXTURES = [ { id: 1, city: 'Buenos Aires', country: 'Argentina', visited: true}, { id: 2, city: 'Cordoba', country: 'Argentina', visited: false}, { id: 11, city: 'Sydney', country: 'Australia', visited: false }, { id: 3, city: 'Santiago', country: 'Chile', visited: true}, { id: 4, city: 'Copenhagen', country: 'Denmark', visited: true }, { id: 5, city: 'Paris', country: 'France', visited: true }, { id: 6, city: 'Bombay', country: 'India', visited: false }, { id: 7, city: 'Delhi', country: 'India', visited: false }, { id: 8, city: 'Kolkata', country: 'India', visited: true }, { id: 9, city: 'Mexico City', country: 'Mexico', visited: false }, { id: 10, city: 'Bangkok', country: 'Thailand', visited: false } ]; TR.recos.FIXTURES = [ { id: 100, type: 'Restaurant', name: 'Chez Louis', address1: '123 Main St.', address2: '1st Floor', city: 'Buenos Aires', country: 'Argentina', postalCode: '12345', phone: '2125551234', website: 'http://www.chezlouis.com', location_id: 1 }, { id: 101, type: 'Hotel', name: 'My Hotel', address1: '345 Main St.', city: 'Buenos Aires', country: 'Argentina', postalCode: '12345', phone: '2125551234', website: 'http://www.myhotel.com', location_id: 1 } ]; </code></pre> <p>Routes:</p> <pre><code>TR.Router.map(function () { this.resource('visited', function () { this.route('recos', {path: '/recos/:location_id'}); }); }); TR.VisitedRoute = Ember.Route.extend({ model: function () { TR.location.find(); return TR.location.filter(function (location) { if (location.get('visited')) { return true; } }); }, renderTemplate: function (controller) { this.render('locations', { controller: controller }); } }); TR.VisitedRecosRoute = Ember.Route.extend({ model: function (params) { return TR.recos.find(params.location_id); } }); </code></pre> <p>Controllers:</p> <pre><code>TR.LocationController = Ember.ObjectController.extend({ showRecos: function (location, controller) { controller.parentController.transitionToRoute(controller.parentController.prefix + '.recos', location.get("id")); } }); TR.LocationsController = Ember.ArrayController.extend({ addLocation: function () { var locationVal = this.get('newLocation'); if (!locationVal.trim()) { return; } var location = TR.location.createRecord({ name: locationVal, visited: this.get('visited') }); this.set('newLocation', ''); // Save the new model location.save(); }, itemController: "location" }); TR.VisitedController = TR.LocationsController.extend({ heading: "Places I've Visited", prefix: 'visited', visited: true }); </code></pre> <p>So, with the above code, only recommendations for Buenos Aires should show. For the other cities, a message should show that tells the user that there are no recommendations.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload