ember.js

Ember js controlling class bindings in repeating component

房东的猫 提交于 2020-01-07 01:49:18
问题 I have a component which is repeating inside an each loop. The component simply displays the title of a post (There could potentially be hundreds). The code below is successfully adding the class 'active' to a title element which is clicked. How can I remove class 'active' from all previous titles when a new one is clicked (So that only one title ever has the class active)? I originally tried doing this on the controller, but I couldn't work out how to set the isActive property on one

Where and how to include Ember model functions

五迷三道 提交于 2020-01-07 01:48:28
问题 I am working on a simple Ember app that shows ID's for list elements. The ID's are computed with simple functions based on the element sequence (and some other simple factors). For example: <div class="content-id element">[ELEMENT ID]</div> <div class="content-name">{{element.name}}</div> I don't want to hardcode the element id's into the JSON object, but rather compute them in a simple function. Would it be best to place this function in the route object or in the component? What's the

How to get page to update with new records from server without a route change?

旧街凉风 提交于 2020-01-06 21:04:32
问题 I have an Ember app that uses server-side storage. In the products route, I have a list of products that I display in my product route (which are fetched in the usual way upon entering the route) {{#each item in sortedProducts}} {{/each}} .... fetch App.ProductRoute = Ember.Route.extend({ model: function(){ return Ember.RSVP.hash({ store: this.store.find('product'), //other code ommitted }) } }) In the controller, I do the sorting sortProperties: ['date:desc'] //dated added sortedProducts:

Ember store query template no model data

别说谁变了你拦得住时间么 提交于 2020-01-06 20:25:15
问题 How come Ember model store query doesn't update template model data and find does? // This doesn't update the template, when loading website no information is displayed but the data is loaded model: function() { var parentModel = this.modelFor("server.view"); return this.store.query("server", { server_address: parentModel.server_address }); } // This works without any problems model: function() { var parentModel = this.modelFor("server.view"); return this.store.find("server", 1); } 回答1: So I

Exclude files from broccoli Ember 2.0

一世执手 提交于 2020-01-06 20:17:41
问题 Hi im kind of new to ember, im looking for a way to tell broccoli not to include my img/ directory, i want to include some default images there which ill be programatically adding to the app <img src='{{model.picture}}'/> And i can see them ok in development but not in production since the name has a hash attaches due to brocolli task, how do i configure my BrocFile to exclude files in the directory i have checked the documentation here https://github.com/rickharrison/broccoli-asset-rev but i

如何确定两个JavaScript对象的相等性?

与世无争的帅哥 提交于 2020-01-06 16:54:09
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 严格的相等运算符将告诉您两个对象 类型 是否相等。 但是,有没有办法判断两个对象是否相等, 就像 Java中 的哈希码 值 一样 ? 堆栈溢出问题 JavaScript中是否存在某种hashCode函数? 与这个问题相似,但需要更多的学术答案。 上面的场景演示了为什么必须要有一个,而我想知道是否有任何 等效的解决方案 。 #1楼 如果您方便使用深层复制功能,则可以使用以下技巧在匹配属性顺序时 仍 使用 JSON.stringify : function equals(obj1, obj2) { function _equals(obj1, obj2) { return JSON.stringify(obj1) === JSON.stringify($.extend(true, {}, obj1, obj2)); } return _equals(obj1, obj2) && _equals(obj2, obj1); } 演示: http : //jsfiddle.net/CU3vb/3/ 理由: 由于 obj1 的属性被一一复制到克隆,因此将保留它们在克隆中的顺序。 并且,当将 obj2 的属性复制到克隆中时,由于 obj1 已经存在的属性将被简单地覆盖,因此它们在克隆中的顺序将得以保留。 #2楼 这是我的版本

Invalidate session with custom authenticator

爱⌒轻易说出口 提交于 2020-01-06 13:52:06
问题 Using ember-cli 0.1.2 and ember-cli-simple-auth 0.7.0, I need to invalidate the session both on client and server. As explained here I need to do something similar to the authenticate method making an ajax request to the server and ensuring its success before emptying the session: import Ember from 'ember'; import Base from "simple-auth/authenticators/base"; var CustomAuthenticator = Base.extend({ tokenEndpoint: 'http://127.0.0.1:3000/api/v1/auth/login', restore: function(data) { },

Invalidate session with custom authenticator

喜夏-厌秋 提交于 2020-01-06 13:51:10
问题 Using ember-cli 0.1.2 and ember-cli-simple-auth 0.7.0, I need to invalidate the session both on client and server. As explained here I need to do something similar to the authenticate method making an ajax request to the server and ensuring its success before emptying the session: import Ember from 'ember'; import Base from "simple-auth/authenticators/base"; var CustomAuthenticator = Base.extend({ tokenEndpoint: 'http://127.0.0.1:3000/api/v1/auth/login', restore: function(data) { },

Why am I getting an error after successful deleteRecord in Ember

狂风中的少年 提交于 2020-01-06 12:51:28
问题 I get this error after calling deleteRecord and then save on an entity. I'm using the DS.RESTAdapter and delete works perfectly well in the backend but the console is throwing this error Error: No model was found for 'id' at new Error (native) at Error.Ember.Error (http://localhost:3000/assets/ember.js?body=1:913:19) at Ember.Object.extend.modelFor (http://localhost:3000/assets/ember-data.js?body=1:9808:33) at JSONSerializer.extend.extractSingle (http://localhost:3000/assets/ember-data.js

Getting “Error: Assertion Failed: calling set on destroyed object” when trying to rollback a deletion

余生颓废 提交于 2020-01-06 08:26:16
问题 I am looking into how to show proper deletion error message in ember when there is an error coming back from the server. I looked at this topic and followed its suggestion: Ember Data delete fails, how to rollback My code is just like it, I return a 400 and my catch fires and logs, but nothing happens, when I pause it in the debugger though and try to rollback, I get Error: Assertion Failed: calling set on destroyed object So A) I cannot rollback B) the error is eaten normally. Here is my