ember.js

Ember - this.get(one from an array)

孤街浪徒 提交于 2019-12-13 05:52:42
问题 So I've got two versions of this question, one a little simplified, one a bit more like what I'm trying to achieve. I have a "student" model and a "score" model. The "student" has many "scores". On the "student" controller, I'm trying to set a computed property "score" equal to a specified one of these "scores". Is there some way I can pass in another argument (eg, so as return the first in the array)? In controllers/student score: function(){ return this.get('scores', 1); }.property('scores'

Obtaining related Ember model data from within a route or component

我们两清 提交于 2019-12-13 05:50:59
问题 Update - partial solution - see below I have a (product category) model with a many to many relationship eg export default DS.Model.extend({ name: DS.attr('string'), products:DS.hasMany('product') }); My category route (product.items) is backed by this model, and it's no problem displaying the related product data: {{#each model.data.products as |item|}} {{item.name}} {{/each}} However, I need to obtain the related data within the child route (product.items.item). The model hook for the route

Setting the inverse option dynamically/conditionally in ember-data?

99封情书 提交于 2019-12-13 05:30:18
问题 I'm trying to implement a full scale friending system with Ember (with friend requests that can be accepted or rejected, the ability to cancel friend requests, and unfriending). In order to do this, I have my Rails backend pass three different friendship arrays via JSON to ember, which are captured in the following ember models (extraneous stuff removed): App.User = DS.Model.extend name: DS.attr('string') friendships: DS.hasMany('friendship', { inverse: 'user' }) requestedFriendships: DS

How does EmberJS select template for a Route?

☆樱花仙子☆ 提交于 2019-12-13 05:23:09
问题 I have these routes defined: this.resource('projects', function() { this.resource('project', { path: ':project_id'}, function() { this.route('details'); this.route('members'); }); }); What I thought was that by convention project.details route would look for "project/details" template. It does but strangely it does not get the correct model. See http://jsbin.com/ELaxigE/19/edit Now instead of providing "project/details" template if I create "project" template then it works. See http://jsbin

Ember-data Serialize/Deserialize embedded records on 3rd level

萝らか妹 提交于 2019-12-13 05:15:28
问题 Pardon me for coming up with this title but I really don't know how to ask this so I'll just explain. Model: Group (has) User (has) Post Defined as: // models/group.js name: DS.attr('string'), // models/user.js name: DS.attr('string'), group: DS.belongsTo('group') // models/post.js name: DS.attr('string'), user: DS.belongsTo('user'), When I request /posts , my server returns this embedded record: { "posts": [ { "id": 1, "name": "Whitey", "user": { "id": 1, "name": "User 1", "group": 2 } } ] }

Ember Controller extend not loading variables into template

♀尐吖头ヾ 提交于 2019-12-13 05:11:34
问题 I've created a mixin , a controller , and a template . // checkIn/index.js.handlebars <div class="page-header text-center"> <h2> Check in for {{#unless checkInSettings.loaded}} <span class="icon-spinner icon-spin"></span> {{else}} <span class="text-info">{{checkInSettings.programName}}</span> - <span class="text-info">{{checkInSettings.programStartDate}}</span> {{/unless}} </h2> </div> // controllers/check_in_controller.js App.CheckInController = Em.Controller.extend(App.LoadCheckInSettings);

Nested URLs: issues with route transition

三世轮回 提交于 2019-12-13 05:01:31
问题 I am currently struggling to get on board with Ember.js and I bumped into an issue with my current routes design, they have nesting URLs, however there are no nesting templates, so their configuration looks like this: this.resource('customer', { path: '/Customer/:id' }); this.resource('employees', { path: '/Customer/:id/Employees' }); Now, at Customers/:id (after submit action) a new Customer instance is created in DS.store and a set of empty Employee objects are added, as well, into the DS

In an ember component template how can I use 'if' to check for at least one of an array having a property equal to X?

蹲街弑〆低调 提交于 2019-12-13 04:59:35
问题 My component is passed a notification . A notification has an account , and an account has many contacts . So I could easily do something like {{#if (is-greater-than notification.account.contacts.length 0)}} <p>stuff</p> {{/if}} To check for the existence of a contact, but what if I wanted to only display if at least one contact has firstName 'John', how could I do this in the component template only? Or if not possible in the template what is the next best approach? I tried having a isHidden

Passing a dynamic parameter different than xyz_id using linkTo in Ember.js

本秂侑毒 提交于 2019-12-13 04:56:47
问题 I've seen a lot of examples of passing dynamic parameters which end with xyz_id being passed where xyz is the "model". However, is there a way to pass an id different than xyz_id? Basically, given this fiddle: http://jsfiddle.net/xcNSa/11/ Can someone please show me how to pass in the video's code and type options as parameters instead of just the id. So, current link titled "Link to myself" points to: http://fiddle.jshell.net/xcNSa/11/show/#/video/1 I'd like it to point to: http://fiddle

Setting a belongsTo Relationship on a Dirty Object in Ember.js

a 夏天 提交于 2019-12-13 04:53:29
问题 I'm using Ember.js 1.0 and Ember-Data 1.0.0beta2. I have a couple of related models: Whistlr.Upload = DS.Model.extend organizations: DS.hasMany('organization') Whistlr.Organization = DS.Model.extend upload: DS.belongsTo('upload') The user creates the Upload within the Organization form via Jquery File Upload. In the success callback, I set the relationship like so: upload = @get('parentView').get('controller').store.createRecord('upload', response.upload) @get('parentView').get('controller')