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 7499255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:46:13+00:00 2026-05-29T19:46:13+00:00

I am populating a JSTree view with ajax commands. My current JS code is

  • 0

I am populating a JSTree view with ajax commands. My current JS code is as follows

$(document).ready(function() {
        $("#navigation").jstree({
            "json_data": {
                "ajax": {
                    "url": function (node) {
                        var nodeId = "";
                        var url = "";
                        if (node == -1) {
                            url = "@Url.Action("BaseTreeItems", "Events")";
                        } else {
                            nodeId = node.attr('id');
                            url = "@Url.Action("EventTreeItems", "Events")" +"?selectedYear=" + nodeId;
                        }
                        return url;
                    },
                    "dataType": "text json",
                    "contentType": "application/json charset=utf-8",
                    "data": function(n) { return { id: n.attr ? n.attr("id") : 0 }; },
                    "success": function() {
                    }
                }
            },
            "themes": {
                "theme": "classic"
            },
            "plugins": ["themes", "json_data", "ui"]
        });
    });

I would like to eliminate the if statement from the “ajax” property and fill it with the JSON data that is coming from the server. The JSON data looks like this

[{"data":{"title":"2012","attr":{"href":"/Events/EventList?selectedYear=2012"}},"attr":{"id":"2012","selected":false,"ajax":"/Events/EventTreeItems?selectedYear=2012"},"children":null,"state":"closed"},.....]

How can I feed the “ajax” property from the json into the “ajax” property in the JSTree?

  • 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-05-29T19:46:19+00:00Added an answer on May 29, 2026 at 7:46 pm

    For future reference I fixed it by doing the following

    .jstree({
                "json_data": {
                    "ajax": {
                        "url": function (node) {
                            var url;
                            if (node == -1) {
                                url = "@Url.Action("BaseTreeItems", "Events")";
                            } else {
                                url = node.attr('ajax');
                            }
                            return url;
                        },
                        "dataType": "text json",
                        "contentType": "application/json charset=utf-8",
                        "data": function(n) { return { id: n.attr ? n.attr("id") : 0, ajax: n.attr ? n.attr("ajax") : 0 }; },
                        "success": function() {
                        }
                    }
                },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am populating a combobox dropdown with node fields from an Xml document. I
I have a Jstree populating a list of items. When I click a node
I am populating a UITableViewController's UITableView through code only. At the bottom of the
I'm populating a combobox with month name as follows:` var engCulture = new CultureInfo(en-US);
I am populating a standard UITableViewCell with an image as follows: cell.imageView.image = [UIImage
I am populating a Dojo Combobox dropdown with values from JSON. The code below
I am populating textboxes with information from a particular node based on it's ConfirmNum
I have a grid view populating by users, i want to add to it
I'm populating a datagrid using Linq--standard kind of stuff (code below). For some reason
I am populating a treeview control, c# visual studio 8, using this code: private

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.