JavaScript vue.js How to call a function inside a for loop and pass the current item? call function inside function python,call function inside function,call

Using vue.js 2, inside a for loop, I need to render a row only if the current iterated item passes some test.

The test is complex so a simple v-if="item.value == x" wont do.

I've written a function named testIssue that accepts the item and returns true or false and tried to use that is av-if like this:

<template v-for="issue in search_results.issues">
  <tr v-if="testIssue(issue)">
     ....
  </tr>
</template>


var releaseApp = new Vue({
  el: '#release-app',
  methods: {
    testIssue: function(issue) {
      console.log(issue);
      console.log('test');
    },
  },
  mounted: function() {},
  data: {
    search_results: {
      issues: []
    },
  }
});

However, testIssue is never called.

If I change the line to <tr v-if="testIssue">, the function is called but then I dont have the issue variable that I need to test.

I also tried <tr v-if="releaseApp.testIssue(issue)">

How can I call a function in a v-if declaration inside a for loop and pass the current item?

Answer:1

Your scenario works with a similar example in this fiddle.

But you can try it this way also:

You can create a custom directive named v-hide and pass issue to it as its value.

Then in the directive you can test for testIssue() and set the particular element's display to none

<template v-for="issue in search_results.issues">
  <tr v-hide="issue">
     ....
  </tr>
</template>


var releaseApp = new Vue({
  el: '#release-app',
  directive:{
    hide: {
        bind(el, binding, Vnode){
            var vm = Vnode.context;
            var issue = binding.value;
            if(vm.testIssue(issue)){
                el.style.display = 'none';
            }
        }
    }
  },
  methods: {
    testIssue: function(issue) {
      console.log(issue);
      console.log('test');
    },
  },
  mounted: function() {},
  data: {
    search_results: {
      issues: []
    },
  }
});
Answer:2

why do we need self referential object in javascript. example let a = {}; a.self = a; now a property self is referring to itself and become circular object. in nodejs when we use routing library ...

why do we need self referential object in javascript. example let a = {}; a.self = a; now a property self is referring to itself and become circular object. in nodejs when we use routing library ...

Using a Array.splice is fine as long as it's a single value. Suppose I have an array with 10 elements and I want to remove element 2,4 and 8, using Array.splice(index,1) in a for loop is a bad idea ...

Using a Array.splice is fine as long as it's a single value. Suppose I have an array with 10 elements and I want to remove element 2,4 and 8, using Array.splice(index,1) in a for loop is a bad idea ...

  1. remove multiple elements from list python
  2. remove multiple elements from array javascript
  3. remove multiple elements from set python
  4. remove multiple elements from list python by index
  5. remove multiple elements from vector c++
  6. remove multiple elements from array swift
  7. remove multiple elements from arraylist java
  8. remove multiple elements from an array
  9. remove multiple elements jquery
  10. remove multiple elements from dictionary python
  11. remove multiple elements from dom javascript
  12. remove multiple elements from array matlab
  13. remove multiple elements from list python using index
  14. remove multiple elements from list r
  15. remove multiple elements from numpy array python
  16. remove multiple elements from list java
  17. remove multiple elements from list c#
  18. remove multiple elements from array php
  19. remove multiple elements from string python
  20. remove multiple elements from array typescript

I have a simple AJAX GET request going to a certain PHP page: $.ajax({ type: "GET", url: "http://example.com/remote.php", success: function(response){ document.getElementById("...

I have a simple AJAX GET request going to a certain PHP page: $.ajax({ type: "GET", url: "http://example.com/remote.php", success: function(response){ document.getElementById("...

  1. from what page to start
  2. php from which page
  3. php check from which page
  4. contact form 7 from which page

const barStream = fs.createWriteStream('bar'); const foo = spawn('foo', [], { stdio: ['ignore', barStream, 'inherit'] }); throws an error: Incorrect value for stdio stream: WriteStream Doing this ...

const barStream = fs.createWriteStream('bar'); const foo = spawn('foo', [], { stdio: ['ignore', barStream, 'inherit'] }); throws an error: Incorrect value for stdio stream: WriteStream Doing this ...