Defining and using controller methods in ember.js
Posted
by
OriginalEXE
on Stack Overflow
See other posts from Stack Overflow
or by OriginalEXE
Published on 2013-11-02T18:48:46Z
Indexed on
2013/11/02
21:54 UTC
Read the original article
Hit count: 197
JavaScript
|ember.js
first of all, I am total noob when it comes to OOP in JS, this is new to me so treat me like a noob.
I am building my first ember.js application and I am stuck (not the first time but I would get unstuck by myself, this is a tough one though).
I have two models: forms entries
Entries is of course in (one to many) relationship to forms, so each form can have as many properties.
Form properties:
id : DS.attr( 'number' ),
title : DS.attr( 'string' ),
views : DS.attr( 'number' ),
conversion : DS.attr( 'number' ),
entries : DS.hasMany( 'entry' )
Entry properties:
id : DS.attr( 'number' ),
parent_id: DS.belongsTo( 'form' )
Now, I have forms route that displays all forms in tabled view, and each table row has some info like form id, name etc. and that works great.
What I wanted to do is display the number of entries each form has. I figured I should do that via controller, so here is my controller now:
// Form controller
App.FormController = Ember.ObjectController.extend({
entriescount: function() {
var entries = this.get( 'store').find( 'entry' );
return entries.filterBy( 'parent_id', this.get( 'id' ) ).get( 'length' );
}.property( '[email protected]_id')
});
Now for some reason, when I use {{entriescount}}
in {{#each}}
loop, this returns nothing. It also returns nothing in single form route. Note that in both cases, {{title}} for example works.
I am wondering, am I going the right way by using controller for this, and how do I get controller to output the data.
Thanks
© Stack Overflow or respective owner