Issues Persist with Bootstrap Tree View - object passed but no output显示

After going through numerous discussions and solving several issues along the way, I have encountered a major problem where there is no output.

As mentioned before, I am utilizing Bootstrap Tree View:

To establish the hierarchical structure required for the tree, it is essential to provide a nested array of JavaScript objects.

For example:

 var tree = [
      {
        text: "Parent 1",
        nodes: [
          {
            text: "Child 1",
            nodes: [
              {
                text: "Grandchild 1"
              },
              {
                text: "Grandchild 2"
              }
            ]
          },
          {
            text: "Child 2"
          }
        ]
      },
      {
        text: "Parent 2"
      },
      {
        text: "Parent 3"
      },
      {
        text: "Parent 4"
      },
      {
        text: "Parent 5"
      }
    ];

The Array Output for My Categories:

 Array
(
    [0] => Array
        (
            [text] => Housing
            [href] => http://localhost/projekte/application/housing/housing
            [tags] => ['5']
            [nodes] => Array
                (
                    [0] => Array
                        (
                            [text] => House
                            [href] => http://localhost/projekte/application/house/house
                            [tags] => ['20']
                        )

                    [1] => Array
                        (
                            [text] => Shared Apartments - Rooms
                            [href] => http://localhost/projekte/application/shared-apartments-rooms/shared-apartments-rooms
                            [tags] => ['19']
                        )

                    [2] => Array
                        (
                            [text] => Apartment
                            [href] => http://localhost/projekte/application/apartment/apartment
                            [tags] => ['18']
                        )

                )

        )
     ...
     // Remaining category arrays excluded for brevity

)

This is the code responsible for displaying the Tree:

 <div class="treeview" id="treeview1">
            <ul class="list-group">
            </ul>
        </div>
        <script type='text/javascript'>
            var js_data = <?php json_encode($tree,JSON_FORCE_OBJECT) ?>;
            var js_obj_data = JSON.parse(js_data );
            function getTree() {
                return js_obj_data;
            }
            $('#treeview1').treeview({data: getTree()});
        </script>

NOTE: Despite my research efforts, I could not find a solution to my dilemma. Any help would be appreciated. Thank you.

Answer №1

Resolution:

  <script type='text/javascript'>
        $(function () {
            var js_information = <?php echo json_encode($tree,JSON_PRETTY_PRINT) ?>;
           //  var js_obj_data = JSON.parse(js_data );
         //   alert(js_data.toSource);
        function retrieveTree() {
            return js_data;
        }
        $('#treeview1').treeview({data: retrieveTree()});
        });
    </script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to display a specific section on an HTML page using AngularJS

Main page content <div class="row"> <div class="col-md-3"> link 1 link 2 link 3 . . . </div> </div> <div class="col-md-9"> <div ng-view></div> </div& ...

I encountered an issue in reactjs where I received the error message: TypeError: this.state.coords.map is not functioning properly

Here is the code snippet I wrote: import React, { Component } from 'react'; class LocationApp extends Component { constructor(props){ super(props) this.state = { coords:[], error:[], } } ...

The custom div slider speed is too quick, specifically when transitioning back from a different browser tab

While observing the code in action, everything seems to work fine but when I switch to another browser tab and come back, the speed of the animation is too fast. Below is the jQuery code snippet: var divId = 1; var lp = 0; $(document).ready(function (){ ...

What flaws are present in this authentication system?

As a developer with a passion for coding, rather than a security expert, I came across The definitive guide to form-based website authentication, which highlighted the importance of SSL or complex algorithms in safeguarding login data from eavesdropping. D ...

The choice between using inline style objects with React or utilizing traditional CSS classes presents distinct advantages and

Is there a discernible difference between utilizing an inline style object for react components and using a normal CSS class through the className attribute? Even when wanting to modify styles based on a specific event, simply changing the className should ...

Enhance your li items with prev and next buttons using PHP or jQuery

I am working on a project where I have a list being populated dynamically with PHP. My goal is to include previous and next buttons within each list item. When an item is clicked, it opens a jQuery modal with a specific href value. How can I add this href ...

Evaluating the functionality of Express Js Server with mocha and chai

I'm currently struggling to properly close the server connection in my Express server when testing it with Mocha and Chai. It seems that even after the test is completed, the server connection remains open and hangs. Index.js const express = require( ...

My handleChange function is inaccessible to the event listener

ParentComponent.js (App.js) import React from "react"; import ChildComponent from "./ChildComponent"; import data from "./data"; import "./styles.css"; class ParentComponent extends React.Component { constructor() ...

The fullcalendar is experiencing difficulties in showing the event

I am facing an issue with Fullcalendar where the events fetched by ajax are not showing up on the calendar. Even though the events are successfully passed and can be displayed in a pop-up, they do not render on the calendar. When manually setting the event ...

What's the best way to transform createHmac function from Node.js to C#?

Here's a snippet of code in Node.js: const crypto = require('crypto') const token = crypto.createHmac('sha1', 'value'+'secretValue').update('value').digest('hex'); I am trying to convert t ...

Exploring nested object values in React Js through iteration

I have been searching extensively for a solution to no avail. I have an object created from fetched data with the following structure: { id: string, title: string, price: { currency: string, amount: number, }, ...

Creating JSON paths conditionally using jq: A comprehensive guide

I have a complex structure of JSON objects that are nested in various levels. { "category1": "value1"`, "category2": { "a": "value2", "b": "value3" }, "category3& ...

Struggling to retrieve data from AJAX POST request [Revised Post]

I am encountering an issue with posting a form using the AJAX POST method in jQuery. I am using the serialize method to retrieve the form data, but it seems to fail. The problem might be related to the JavaScript files of the Steps Wizard plugin that I am ...

Guide to sending a post request with parameters in nuxt.js

I am trying to fetch data using the fetch method in Nuxt/Axios to send a post request and retrieve specific category information: async fetch() { const res = await this.$axios.post( `https://example.com/art-admin/public/api/get_single_cat_data_an ...

Insert information into a nested array using Mongoose

I'm encountering an issue with my code, even though I know it may be a duplicate. Here is the snippet causing me trouble: exports.addTechnologyPost = function(req, res){ console.log(req.params.name); var query = { name: 'test ...

Leveraging ng-class for designing a favorite symbol

How can I implement ng-class to toggle an icon when it is clicked, taking into account whether it is stored in local storage? For example, changing the favorite icon from outline to solid upon user click. Below is my current implementation using ng-class ...

Creating a promise in an AngularJS factory function to perform an operation

When working within an Angular factory, I am tasked with creating a function that must return a promise. Once the promise is returned, additional functionality will be added. SPApp.factory('processing', ['$http', '$rootScope&a ...

Steps for incorporating a legitimate JSON string into an object

My code currently looks like this: type Info struct { Ids []string `json:"ids"` assignment string `json:"assignment"` } However, the assignment field contains a large hardcoded JSON string that is read from a file. In ...

In JavaScript, a prompt is used to request the user to input a CSS property. If the input is incorrect,

Implement a while loop that continuously prompts the user to enter a color. If the color entered matches a CSS property such as blue, red, or #000000: The background will change accordingly, but if the user enters an incorrect color, a message will be dis ...

What is the best way to include an icon before each option in a VuetifyJS combobox?

I'm looking to enhance the combobox feature in VuetifyJS by adding an icon before each option in the dropdown menu. Can someone guide me on how to achieve this functionality? You can check out a sample of the combobox on CodePen here: https://codepen. ...