backbone.js - Filtering out duplicate entries in collection -
when populating drop downwards list backbone collection, how go not adding duplicate entries, e.g. entries same (in case) organisation name?
currently have this, populates drop downwards list:
[[ _.each(facilities.tojson(), function(item) { ]] <option value="{{ item.id }}">{{ item.organisationname }}</option> [[ }); ]]
you implement helper method on collection:
var facilities = backbone.collection.extend({ getuniquebyproperty: function(propertyname) { homecoming _.unique(this.tojson(), function(item) { homecoming item[propertyname]; }); } });
usage:
[[ _.each(facilities.getuniquebyproperty('organisationname'), function(item) { ]] <option value="{{ item.id }}">{{ item.organisationname }}</option> [[ }); ]]
/code sample not tested
backbone.js
No comments:
Post a Comment