Notice: The Monaca & Onsen UI Community Forum is shutting down.

For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.

Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.

Accessing Vue-data while in $ons.notification



  • How can I retrieve from data while in this.$ons.notification.confirm callback?

    <script>
    export default {
      name: 'groups',
      data () {
        return {
          myGroups: JSON.parse(localStorage.getItem("myGroups")),
        }
      },
      methods: {
        deleteGroup: function(groupId) {
    
          console.log(this.myGroups); // ****** OKE here ******
    
          this.$ons.notification.confirm('Are you sure?',
              { modifier: 'material',
                cancelable: true,
                title: 'Delete group?',
                buttonLabels: ['Yes', 'No'],
                callback: function(answer) {
                    if (answer == 0) { //YES
                      console.log(this.myGroups) // ***** Undefined here ?? *****
                    }
                }
              })
        }
    }
    </script>
    


  • The above is probably not OnsenUI related and has something to do with scope/async.
    But doing it like this:

    $ons.notification.confirm('Are you sure?',
              { modifier: 'material',
                cancelable: true,
                title: 'Delete group?',
                buttonLabels: ['Yes', 'No']}
     ).then((response) => {
        console.log(this.myGroups) // ***** Works FINE !!! *****
      });
    

    as stated here: https://onsen.io/v2/api/vue/$ons.notification.html

    it works fine…


  • Onsen UI

    @Bassie JavaScript issue: Use an arrow function instead. Normal functions create new contexts but arrow functions don’t.