Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
TypeError: this.selectedNodes.value is not iterable

So I am working with v-network-graphs to create graphs in the front end using Vue. I have defined my data as

data(){
    return{
      test: test_data,
      nodes:{},
      edges:{},
      nextNodeIndex: Number,
      selectedNodes: ref<string[]>([]),
      selectedEdges: ref<string[]>([]) 
    }
  }

and my methods are defined as

methods: {
    g(){  
      this.nodes = reactive(this.test.nodes)
      this.edges = reactive({ ...this.test.edges })
      console.log(this.nodes)
      console.log(this.edges)

      this.nextNodeIndex = ref(Object.keys(this.nodes).length + 1)     
    },
    addNode() {
      const nodeId = this.nextNodeIndex.value 
      this.nodes[nodeId] = {
        name: String(nodeId),
        size: 16,
        color: "blue",
        label: true
      } 
      this.nextNodeIndex.value++ 
      console.log(this.nextNodeIndex)
    },
    removeNode() {
      for (const nodeId of this.selectedNodes.value) {
        delete this.nodes[nodeId] //Delete the selected node, by their ID
      }
    },

Now when I try to remove a node I am getting the error this.selectedNodes.value is not iterable , how should I define selectedNodes then?

https://dash14.github.io/v-network-graph/examples/operation.html#add-remove-network-elements

The above link has an example on how to write remove edge function using the library. I am doing the same, but I want to write the function inside a method as I am working in a Vue project. I am new to Javascript and Vue so any suggestions are greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your example is using OptionsAPI data function to create state which is reactive and the guide that you are referring to is using a Script setup that requires the use of ref() function to create reactive variables.

Because data returns object state that is already reactive, the use of ref within it is redundant and its properties will still be accessible via the . notation without the use of value.

So in your example, you should change the following:

for (const nodeId of this.selectedNodes.value) {

to

for (const nodeId of this.selectedNodes) {

And you can additionally replace the following two properties in data:

selectedNodes: ref<string[]>([]),
selectedEdges: ref<string[]>([])

to

selectedNodes: [],
selectedEdges: []

Hope this helps you!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!