jeudi 17 décembre 2015

Computed property for element in array

I'm trying to make a computed that should return true if a given string is present in an array.

My model has a property on it that is an array of user_id's that look something like this

"item_bid_history": [
  562,
  697,
  13193
]

I can get the currently logged in user's id which would be 13193

Currently I have something like this

bidding: Ember.computed('item.item_bid_history','userService.user_id',function(){
    return Ember.$.inArray(this.get('userService.user_id'),this.get('item.item_bid_history')) > -1;
})

Maybe I'm doing that wrong but even if I attempt to console.log the value of inArray I always get -1 even though the user_id is in some of the item's item_bid_history arrays

Is there maybe a macro that will do this for me or am I just not creating the computed properly?




Aucun commentaire:

Enregistrer un commentaire