I'm trying to filter the result of my hasMany-Array async-get with filterBy and condition "isRoot" == true. The "isRoot" property is a computed property and it seems that the filterBy function of ember doesn't wait for the promise to resolve. Here my code:
Model for Directory
App.Directory = DS.Model.extend(App.ModelEventHandler, {
name: DS.attr('string', {defaultValue: ''}),
users: DS.hasMany('user', {async: true}),
isRootOfShare: DS.attr('boolean', {defaultValue: false}),
directories: DS.hasMany('directory', {async: true, inverse: 'directory'}),
directory: DS.belongsTo('directory', {async: true, inverse: 'directories'}),
shares: DS.hasMany('share', {async: true}),
files: DS.hasMany('file', {async: true}),
isRoot: function () {
var directoryPromise = this.get('directory');
return directoryPromise.then(function (directory) {
var isRoot = directory === null;
return isRoot;
}.bind(this));
}.property('directory')}
Model for User
App.User = DS.Model.extend(App.ModelEventHandler, {
// Attributes begin
email: DS.attr('string'),
isCurrentUser: DS.attr('boolean', {defaultValue: false}),
// Relationships
directories: DS.hasMany('directory', {async: true}),
shares: DS.hasMany('share', {async: true}) }
The statement I'm using to filter the directories:
user.get('directories').then(function (directories) {
//TODO: Fix isRoot
var filteredDirectories = directories.filterBy('isRoot', true);
return filteredDirectories;
});
Someone here with knows a solution for my problem? Thx in advance!
Aucun commentaire:
Enregistrer un commentaire