How to use indexof on array derbyjs -


i have array passed template , want see if have value stored in it:

{{each _page.friends #friend}}     {{if _page.user.friends.indexof(#friend.id)<0}}         <button>add</button>     {{else}}         friends     {{/if}} {{/each}} 

apparently indexof isn't function, array (_page.user.friends) seem exist can use own {{each}}....

is there way this? or perhaps better way?

i not see support indexof mentioned in derby view documentation. however, can use view function determine whether friend or not.

// in view {{each _page.friends #friend}}   {{if isfriend(_page.user.friends, #friend.id)}}      <button>add</button>   {{else}}     friends   {{/if}} {{/each}}  // in controller friendlistcontroller.prototype.isfriend = function(friends, friendid) {   return friends.indexof(friendid) > 0; }; 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -