Quantcast
Viewing all articles
Browse latest Browse all 58

jsTree - can I load data from the viewbag?

Hi All

I'm just trying out the jsTree for the first time and like what I'm seeing. I've got it loading and formatting as I want and have it loading it's data using an ajax query to a method in my controller:-

Code:

    <script type="text/javascript">
        $(function () {
            $("#ProductInterests").jstree
                ({
                    "core" : { "themes" : { "icons" : false }},
                    "plugins": ["checkbox"],
                    "core" :
                        {
                            "data": { 'url': '/Lead/GetProductInterestsJson', 'dataType': 'json' }
                        }

                });

        });
    </script>

The thing is, this is on a view that's being served up from an MVC controller. The controller populates a bunch of Select Lists into the ViewBag which the View then uses to populate various drop downs. It feels natural to populate the tree view in a similar way, i.e. by putting the necessary data into the ViewBag and then using that to populate the data in the View. Somehow having the View call to a method in the controller class just feels a bit odd in this circumstance.

I've had a shufty at the jsTree documentation and a bit of a play with the syntax to see if I can get it to load from the ViewBag but I don't think it's supported. I thought I'd post here, though, to see if anyone knew different.

edit> I should probably specify that this is jsTree3, found here. (I wasted a lot of time trying to get code snippets from previous versions to work before I figured out I was being a numpty)

Viewing all articles
Browse latest Browse all 58

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>