question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"this" not set as underlying vm for getFilterData functions

See original GitHub issue

It seems “this” from the vue instance vm is not made available to the getFilterData functions. No error is thrown because it is just filtering on “undefined”. Filtering works when directly inserting text:return el.description.includes('hello').

data: function () {
  return {
    searchStr: null,
    option: {
      getFilterData: {
        "contains": function(el) {
          console.log(this.searchStr) // undefined when called
          return el.description.includes(this.searchStr)
        }
      }
    }
  }
});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
David-Desmaisonscommented, Feb 10, 2017

Here you, here is the corrected fiddle:

https://jsfiddle.net/dede89/w1tbv83L/7/

Tweaks:

  1. getFilterData and getSortData were not defined in data , so I added filterData and sortData
  2. v-for="(val, key) key and val were inverted
  3. To have the correct context in the getFilterData contains function, I used ES6 arrow function to capture viewModel context (you can do it by hand if you use ES5 using var ctx=this...):
getFilterData: {
    "show all": function() {
         return true;
   },
    "contains": (el) => {
         return el.description.includes(this.searchStr)
   }
 },

And it worked like a charm…

1reaction
MintyOrbcommented, Feb 10, 2017

Thank you David! I realized it was the same issue shortly after posting but wouldn’t have thought to use a method on my own. And again, thanks for producing this component- it’s very handy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Microsoft Azure Reviews - G2
Filter 1493 reviews by the users' company size, role or industry to find out how Microsoft ... Azure Virtual Machines are very easy...
Read more >
Agilent_E1430A_Manual.pdf - ArtisanTG
The C Interface Libraries for the Agilent E1430A are a set of functions that allow you to program the register-based Agilent E1430A at...
Read more >
UnixWare 7.1.4+ Installation and Update Guide
This Install CD: A new UnixWare 7.1.4+ Install CD that sets up a basic UnixWare ... These packages and sets do not need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found