ember.js

Get helper in hbs when getting nested object

我怕爱的太早我们不能终老 提交于 2020-01-15 02:55:09
问题 suppose I have the following objects: image: { size: { l: { url: 'l.jpg', }, m: { url: 'm.jpg', }, s; { url: 's.jpg', } } }, mySize: 'm' If I want to get corresponding image url in my template, how should I do that? I tried: {{get image mySize 'url'}} but it does not work. I can get the url I want by typing like this: {{get (get image mySize) 'url')}} However this is a very unintuitive and ugly workaround. Is there any a better way? Thank you. 回答1: You need to use the concat helper along with

ember-data DS.RESTAdapter causes TypeError

…衆ロ難τιáo~ 提交于 2020-01-14 14:32:50
问题 I'm trying out Ember.js with ember-data, and I have the following application defined: window.App = Ember.Application.create() App.store = DS.Store.create revision: 4 adapter: DS.RESTAdapter.create { bulkCommit: false } App.Source = DS.Model.extend # options primaryKey: '_id' # fields name: DS.attr 'string' raw_text: DS.attr 'string' App.sourcesController = Ember.ArrayProxy.create content: App.store.findAll App.Source App.ListSourcesView = Ember.View.extend templateName: 'app/templates

Ember model only loads last record

时间秒杀一切 提交于 2020-01-14 13:36:30
问题 I'm trying to reproduce Railscasts 410 example (called Raffler ), changing the setup for last versions and to match my habits: Ember 1.0.0-rc.6 Rails 4.0.0 Mongoid master (4.0) Haml 4 Emblem 0.3.0 In this example project, we create a simple model Entry that calls a small Rails Rest API. Everything works as expected, except that calling Raffler.Entry.find() to get all entries only loads the last record. Here is my model : Raffler.Entry = DS.Model.extend name: DS.attr('string') winner: DS.attr(

Ember model only loads last record

Deadly 提交于 2020-01-14 13:36:10
问题 I'm trying to reproduce Railscasts 410 example (called Raffler ), changing the setup for last versions and to match my habits: Ember 1.0.0-rc.6 Rails 4.0.0 Mongoid master (4.0) Haml 4 Emblem 0.3.0 In this example project, we create a simple model Entry that calls a small Rails Rest API. Everything works as expected, except that calling Raffler.Entry.find() to get all entries only loads the last record. Here is my model : Raffler.Entry = DS.Model.extend name: DS.attr('string') winner: DS.attr(

Ember Data delete fails, how to rollback

不问归期 提交于 2020-01-14 08:35:47
问题 If I call destroyRecord and it fails on the server, it also disappears from the local store and from the UI. I need to somehow "rollback" if delete fails. I have tried something like this. item.destroyRecord().then(function () { Notify.success("item removed"); }).catch(function (response) { //NEED TO ROLLBACK HERE - ANY IDEAS? Notify.error('Failed to remove!'); }); 回答1: Firstly, rollback with relationships doesn't fully work in ember data, secondly the newer versions of ember data handle this

Ember.js shorthand for common computed property pattern

二次信任 提交于 2020-01-14 08:13:18
问题 In Ember.js I find myself defining computed properties that look like this: someProp: function(){ return this.get('otherProp'); }.property('otherProp') or someProp: function(){ return this.get('otherObject.prop'); }.property('otherObject.prop') Is there a shorter way to write computed properties that follow these patterns? 回答1: Having researched a little bit you could dry this a little up by doing the following with the help of Ember.computed.alias : someProp: Ember.computed.alias(

Ember.js shorthand for common computed property pattern

删除回忆录丶 提交于 2020-01-14 08:11:43
问题 In Ember.js I find myself defining computed properties that look like this: someProp: function(){ return this.get('otherProp'); }.property('otherProp') or someProp: function(){ return this.get('otherObject.prop'); }.property('otherObject.prop') Is there a shorter way to write computed properties that follow these patterns? 回答1: Having researched a little bit you could dry this a little up by doing the following with the help of Ember.computed.alias : someProp: Ember.computed.alias(

Ember events other than click

ⅰ亾dé卋堺 提交于 2020-01-14 06:07:47
问题 Edit: found the answer here: Using Ember.js, how do I run some JS after a view is rendered? In the mapView didInsertElement: function() { this._super(); map_initialize(); }, *********** original post **************** I'm pretty new to js and am trying ember.js. I am trying to use the google maps api to show a map. Normally you should initialize the map with <body onload="map_initialize()"> but as the map div that will receive the map is part of an ember view template it is not yet in the DOM

Ember events other than click

回眸只為那壹抹淺笑 提交于 2020-01-14 06:07:32
问题 Edit: found the answer here: Using Ember.js, how do I run some JS after a view is rendered? In the mapView didInsertElement: function() { this._super(); map_initialize(); }, *********** original post **************** I'm pretty new to js and am trying ember.js. I am trying to use the google maps api to show a map. Normally you should initialize the map with <body onload="map_initialize()"> but as the map div that will receive the map is part of an ember view template it is not yet in the DOM

Ember events other than click

北城以北 提交于 2020-01-14 06:07:25
问题 Edit: found the answer here: Using Ember.js, how do I run some JS after a view is rendered? In the mapView didInsertElement: function() { this._super(); map_initialize(); }, *********** original post **************** I'm pretty new to js and am trying ember.js. I am trying to use the google maps api to show a map. Normally you should initialize the map with <body onload="map_initialize()"> but as the map div that will receive the map is part of an ember view template it is not yet in the DOM