• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

getting id is undefined after running function

April 10, 2020 by

Questions › getting id is undefined after running function
0
Vote Up
Vote Down
Garmaine asked 4 years ago

I'm trying to remove items from a group and automatically delete the group if no items are left. When I do the function runs successfully but vue gives me this error saying that id is not defined.

basically i'm not sure why it's trying to grab an id to execute anything, it should already be finished.

this error doesn't happen if I manually delete a group, only if there are 0 items left in the array and the group deletes.

maybe this is a runtime problem? I'm not too sure.

vue.js:634 [Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'id' of undefined"

(found in <Root>)
warn @ vue.js:634
logError @ vue.js:1893
globalHandleError @ vue.js:1888
handleError @ vue.js:1848
invokeWithErrorHandling @ vue.js:1871
invoker @ vue.js:2188
original._wrapper @ vue.js:7547
vue.js:1897 TypeError: Cannot read property 'id' of undefined
    at Vue.leaveExclusionGroup (index.html:764)
    at click (eval at createFunction (vue.js:11649), <anonymous>:3:4956)
    at invokeWithErrorHandling (vue.js:1863)
    at HTMLSpanElement.invoker (vue.js:2188)
    at HTMLSpanElement.original._wrapper (vue.js:7547)

I am currently checking an array of students and removing them by id onclick, then if none are left in a group the group gets removed from the list of groups.

I'm not sure why id is undefined as this function does not run again until I select a student

here is my method.

 leaveExclusionGroup: function(groupID, studentID){
                        //console.log(groupID, studentID)
                        let index = this.exclusionGroups[groupID-1].students //this is an array

                        for(var i = 0; i< this.exclusionGroups[groupID-1].students.length; i++){
                            console.log(index[i])
                            if( index[i].id === studentID){
                                index.splice(i,1)
                            }

                            if(this.exclusionGroups[groupID-1].students === undefined || this.exclusionGroups[groupID-1].students.length === 0){
                                console.log('running remove')
                                this.removeExclusionGroup(groupID)
                            }
                        }                        
                    },

and here is the remove Exclusion group method that runs if there aren't any students left and we can remove the group

  removeExclusionGroup: function(id){

                   console.log(id)
                   for(var i = this.exclusionGroups.length - 1; i >= 0; i--) {
                        if(this.exclusionGroups[i].id === id) {
                            this.exclusionGroups.splice(i, 1);
                            console.log(this.exclusionGroups)
                            }
                        }  
                        this.isHidden = false      
                    },

                    displayModal: function(){
                        $('#myModal').modal('show')
                    },
Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: id, javascript, vue.js

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Copyright © 2023