We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    My context menu for items in a tree view of my CMP stil generates the following Javascript error when clicking any of the menu items:

    Uncaught TypeError: Object function(itm,e) { this.updateTariff(itm,e); } has no method 'apply'
    


    I’ve been looking everywhere for clues but have no idea how to tackle this one ... huh
      MODx Revolution / MAMP / OS X
      • 27519
      • 275 Posts
      I based my tree view implementation on the Gallery package.

      After some investigation of the generated JSON of the nodes in my tree I noticed the following subtle but maybe important difference with the JSON generated by the Gallery app:

      In "Gallery" the following is generated for the context menu of an album:
      {"text":"Update Album","handler":function(itm,e) { this.updateAlbum(itm,e); }}
      


      In my implementation:
      {"text":"Update Tariff","handler":"function(itm,e) { this.updateTariff(itm,e); }"}
      


      For some reason an extra set of quotes is added around the the handler function. Could this cause the Javascript exception I get when clicking my menu options?

      In the "Gallery" application a call to $this.toJSON() is used while I use the json_encode() function of PHP.


        MODx Revolution / MAMP / OS X
        • 28215
        • 4,149 Posts
        splittingred Reply #3, 16 years ago
        Yes. You’ll need to use $this->toJSON(), which gets around that bug by allowing JS "literals" (this., etc).
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 27519
          • 275 Posts
          Thanks for the reply. However, there’s still a problem.

          I do the following in my getNodes.php:

          $node = new TreeNode();
          // Setup the popup menu that allows for updating or deleting
          $node->menu = array('items' => array());
          $node->menu['items'][] = array('text' => 'Update','handler' => 'function(itm,e) { this.updateTariff(itm,e); }',);
          $node->menu['items'][] = '-';
          $node->menu['items'][] = array('text' => 'Remove','handler' => 'function(itm,e) { this.removeTariff(itm,e); }',);
          


          It’s basically the same thing as you do in your Gallery app. Only difference is that you transform your Album directly into an array while I use a TreeNode class to hold the data for the tree. Reason for this is my nodes at various levels are not of the same class as you have in your app.

          Now when I use toJSON() I get a Javascript exception:

          Uncaught SyntaxError: Unexpected token )

          Any ideas?
            MODx Revolution / MAMP / OS X