Add count as property to javascript object -


i have 2 arrays:

  • one categories
  • one datarecords

every data record belongs specific category.

with every use of filter (e.g. searchfield) on datarecords, want add total count of records per category each category-object, can display them on every tab-pane (e.g. text: algemeen, value: 'general, countfiltered: 2)

i made fiddle this.

till no count-filtered, locally constant error corresponding line 78 in fiddle:

uncaught (in promise) type error: cannot read property '0' of undefined

how can achieve this?

this isn't think here:

var filtered = results.filter(function (results) {     return (results.category.tolowercase() == this.categories[cat].value.tolowercase()); }); 

you can either pass in thisarg filter:

var filtered = results.filter(function (results) {     return (results.category.tolowercase() == this.categories[cat].value.tolowercase()); }, this); 

or in es6 can use arrow function:

var filtered = results.filter(     results => results.category.tolowercase() == this.categories[cat].value.tolowercase()  ); 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -