ember.js

Listening when new records are added to the store via a computer property

这一生的挚爱 提交于 2019-12-13 01:19:51
问题 I am pushing records into my store using websockets. I am displaying items on the screen via a handlebars template {{#each item in items}} <div>{{item.name}}</div> {{/each}} In my controller I have the items collection items : function() { var items = this.store.find('items'); return items.filterBy({type : "NEW"}); }.property() Now, when new records are added to the store, I need to update the items automatically. items : function() { var items = this.store.find('items'); return items

Trouble accessing controller's computed property from view

和自甴很熟 提交于 2019-12-13 01:14:28
问题 My controller has a computed property: App.IndexController = Ember.ArrayController.extend({ grandTotal: function () { return this.getEach('total').reduce(function(accum, item) { return accum + item; }, 0); }.property('@each.total'), }); but I'm having trouble accessing it with my view. Here's my view: App.SummaryView = Ember.View.extend({ templateName: 'summary', companiesChanged: function() { Ember.run.once(this, 'logCompanies'); }.observes('controller.@each'), logCompanies: function() {

Running “ember server” fails with error

人盡茶涼 提交于 2019-12-13 00:55:28
问题 I'm trying to get an existing ember app running locally for development, but when I run "ember server" from inside the app directory, I get this error: version: 0.0.39 Livereload server on port 35729 Serving on http://0.0.0.0:4200 EACCES, unlink 'dist/assets/.gitkeep' Error: EACCES, unlink 'dist/assets/.gitkeep' Per this thread https://github.com/stefanpenner/ember-cli/issues/381 I tried doing the following: npm uninstall -g ember-cli rm -rf node_modules npm cache clear npm install -g ember

Extending link-to

强颜欢笑 提交于 2019-12-13 00:42:40
问题 I'm trying to create a custom link-to helper that will conditionally add query-params depending on the presence of a property. Right now, I'm getting an error: Uncaught TypeError: Cannot read property 'options' of undefined . I've traced that to the line var options = parameters.options in the function resolvedParams . Here's my code: In app/components/foo-link.js : export default Ember.LinkView.extend({ init: function() { this._super(); } }); In the template: {{foo-link title='Bar'

Sending action to Ember.StateManager : is goToState mandatory?

佐手、 提交于 2019-12-13 00:29:24
问题 In the documentation of Ember.StateManager it's said that : "Inside of an action method the given state should delegate goToState calls on its StateManager". Does it mean that if I send an action message, I necessarily need to transit to another state. Is it possible to stay in the same state but doing some task by sending an action ? For example, I'm in a state "loading" and I run two actions "preprocess" and "display". 回答1: When dealing with statecharts in general, you can do whatever you

Access item controller in view

馋奶兔 提交于 2019-12-12 23:08:45
问题 I have the following setup: App.AreasController = Ember.ArrayController.extend({ itemController: 'area' }); // In my project route: setupController: function(controller, model) { this.controllerFor('areas').set('content', model.areas); } In my view I am now editing my App.Areas , and would like to invoke a controller method (of the itemController) for a given area from my view. How do I go about that? If I try to access the controller area.get('controller') (where area represents one item

child records and ember model

安稳与你 提交于 2019-12-12 21:28:53
问题 [Update] Thanks for the help so far. I've been able to create a new Post record with an embedded Comment record with static data. Via this method: App.CommentsController = Ember.ArrayController.extend({ needs: "post", actions: { addComment: function() { var post = App.Post.create({ title: 'static post' }); post.get('comments').create({ message: 'static message' }); post.save(); } } }); But I'm falling short figuring out how to retrieve the current Post via the CommentsController or Route in

Ember.js textField change event

安稳与你 提交于 2019-12-12 21:23:50
问题 I just start to learn ember.js Why this code http://jsfiddle.net/alexchetv/RVNzP/ don't work properly -- App.MyTextField.change() execution is triggered only after MyTextField loses focus? Alternative code with the same functionality works as expected. 回答1: Keep in mind that handlers on your Ember.Views (change, select, click, etc) are bound to normal HTML DOM events. "onchange" only gets called on an input field when the field loses focus and has changed, not any time the value is modified.

Ember re render component

六眼飞鱼酱① 提交于 2019-12-12 20:23:40
问题 I have a component with a jquery menu that transforms the DOM. I need to re render the component for initiate the structure again. The jquery menu doesn't work dinamically, so I need to re render the component. //Parent Component hbs <div id="container"> {{menu-jquery model=model}} </div> //Parent Component js export default Ember.Component.extend({ refreshMenuData(){ callToServer()// ajax call updateModel()// generate model from ajax response -> //how to delete and create menu component? or

Ember CollectionView with views that have different templates

非 Y 不嫁゛ 提交于 2019-12-12 20:08:26
问题 Given that I have this code: Ember.App.View = Ember.View.extend({ templateName: "templateA" }); Ember.App.View = Ember.View.extend({ templateName: "templateB" }); Ember.App.ViewC = Ember.CollectionView.extend({ itemViewClass: "Ember.View", contentBinding: "SomeController" }); Is there a way to add views with different templates to CollectionView? 回答1: Another solution is to use ghempton/ember-layout, see http://jsfiddle.net/pangratz666/XhfYy/: App.ViewA = Ember.View.extend({ templateName: