Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7973633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:09:42+00:00 2026-06-04T08:09:42+00:00

I am developing a javascript menu (using jQuery). As an example, the below is

  • 0

I am developing a javascript menu (using jQuery).

As an example, the below is the structure of the items object I would pass to my custom function which then creates the menu.

var items = {
    0: {
        name: 'file',
        submenu: {
            0: {
                name: 'open',
                hasSubitems: true,
                subitems: {
                    0: {
                        name: 'file',
                        hasSubitems: false,
                        callback: function() { alert('you opened a file!'); }
                    },
                    1: {
                        name: 'project'
                        hasSubitems: false,
                        callback: function() { alert('you opened a project!'); }
                    }
                }
            },
            1: {
                name: 'exit',
                hasSubitems: false,
                callback: function() { alert('you logged out!'); }
            }
        }
    },
    1: {
        name: 'edit',
        submenu: {
           ...
        }
    }
}

I would like to be able to store the above into a database, including their prospective callbacks. I intend to create an interface to build the menus dynamically and such.

I realize I could create a JSON string and store it that way, but then what about the callback functions? I have been recommended against using eval several times, so in what other ways might people safely store this information in a database so it can be called upon later?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:09:43+00:00Added an answer on June 4, 2026 at 8:09 am

    JSON is language neutral (despite the name), and as such it only supports primitive values. Callback functions are language specific (javascript in this case), and so they cannot be included in anything that needs to be interpreted as pure JSON.

    I recommend pulling your callback code out of here, and instead include necessary parameters that you would need to distinguish each one. Then, run this JSON object through a JS template engine (like Handlebars.js) with helper functions rather than your callbacks. These can be invoked with the parameters you used to replace your callback functions in your (now valid) JSON object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a DHTML/Javascript application which relies on some advanced features (DOM manipulation,
I'm developing a site in javascript and jquery. Sometimes when I refresh I just
i am developing a gadget and i am using JavaScript to change innerHTML of
I am developing a user control (ascx) in ASP.NET which uses javascript for manipulating
I was developing an application which uses the places API through the Javascript Library
I am developing a javascript application which - among a lot of other controls
I am developing some JavaScript that should work with either Prototype.js or JQuery, thus
I am currently developing a JavaScript (Sencha) app on my Mac which interfaces with
I'm developing a simple JavaScript (jQuery) slide show. I wanted to use JSON to
So I'm developing a Sencha (Javascript) app which needs to make Ajax http requests

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.