ember.js - I need some ideas for this. Emberjs -
i have helper named format-log
//format-log.js import ember 'ember'; export function formatlog(text) { var hashtag = text.match(/[#]\w+/g); var newtext = text; if (hashtag !== null && hashtag !== undefined) { ( var = 0; < hashtag.length; i++){ newtext = newtext.replace(hashtag[i], "<a href='' class='hash'>"+ hashtag[i] +"</a>"); } return newtext; }else{ return text; } } export default ember.handlebars.makeboundhelper(formatlog);
when make new log, have need add hashtag example
"this example #log"
that text go-through helper , returns format
"this example < href="">#log< /a>"
i wanna filter log contains same hashtag make trends twitter, using ember cli , ember-data
my model
//log.js import ds 'ember-data'; export default ds.model.extend({ text: ds.attr('string'), date: ds.attr('date') });
you filter on hashtag first defining hashtags
property on model return hashtags found in text, example:
//log.js import ds 'ember-data'; export default ds.model.extend({ text: ds.attr('string'), date: ds.attr('date'), hashtags: function() { // return array of hash tags in text, ie ['#tag1','#tag2'] var text = this.get('text') || ''; return text.match(/#\w+/g) || []; }.property('text') });
you can filter multiple log models hashtag doing (for example in controller):
modelscontainingtesttag: ember.computed.filter('logs', function(log) { return log.get('hashtags').contains('#test'); })
where logs
refering array of log models.
this start, example concatenate hashtags of models hashtags (using uniq()
eliminate duplicates). , hashtags above filtering or sort of counter.