在路线emberjs获得商店attr

时间:2015-06-13 23:14:30

标签: javascript ember.js ember-data

我使用以下方式提取用户:

library(plyr) res <- dlply(dat, .(Group), function(x) unique(x$Name)) res[["4"]] # [1] B E # Levels: A B C D E ## If you want to extract all the groups with a "B" Name inds <- unlist(lapply(res, function(x) "B" %in% x)) inds # 1 2 3 4 # FALSE FALSE FALSE TRUE ## and to extract that Group names(inds)[inds] # [1] "4"

这是用户模型:

var user  = this.store.find('user', user_id);

我试图运行一个之前的模型,我检查用户是否是管理员,然后做一些事情,如果它的真或假,例如:

export default DS.Model.extend({
  username: DS.attr('string'),
  email: DS.attr('string'),
  first_name: DS.attr('string'),
  last_name: DS.attr('string'),
  password: DS.attr('string'),
  is_admin: DS.attr('boolean')
});

我也尝试过这样做:

beforeModel: function(){
    var user  = this.store.find('user', 1);

    if(user.get('is_admin')){
        return 'do something since they are an admin';
    }
},

如何在路线中获取beforeModel: function(){ var user = this.store.find('user', 1); return user.then(function(response){ if(response.is_admin){ return 'do something since they are an admin'; } }); }, 属性?

1 个答案:

答案 0 :(得分:0)

您可以在路线中定义isAdmin属性,并在user承诺解决时设置。

//route
isAdmin: false,
beforeModel: function() {
  var self = this; 
  return this.store.find('user', 1).then(function(user){
    self.set('isAdmin', user.get('is_admin'));
  }, function(){
    // on reject
  })
}