dimanche 24 mai 2015

jsTree 3 - How do I pre-check an item without selecting it

I'm using jsTree 3 and trying to pre-check some lines based on a criteria.

Here's how I configure the tree:-

    $(function () {
        $("#ProductInterests").jstree
            ({
                "core" : { "themes" : { "icons" : false }},
                "plugins": ["themes", "html_data", "checkbox"]
            });

    });

I've then found three suggested solutions elsewhere on the net (the first half of the if should result in checked nodes and the second should result in unchecked ones):-

<ul>
    @foreach (var productGroup in ViewBag.ProductGroups)
    {
        <li class="jstree-open">@productGroup.Name
            <ul>
                @foreach (var product in productGroup.Products)
                {
                    if (Model.LeadProductInterests.Any(lpi => lpi.ProductID == product.ID))
                    { 
                        <li data-jstree='{"selected":true}'>@product.Name</li>
                        <li data-jstree='{"state":{"checked":true}}'>@product.Name</li>
                        <li class="jstree-checked">@product.Name</li>
                }
                    else
                    { 
                        <li data-jstree='{"selected":false}'>@product.Name</li> 
                        <li data-jstree='{"state":{"checked":false}}'>@product.Name</li>
                        <li>@product.Name</li>
                    }
                }
            </ul>
        </li>
    }
</ul>

Of the three approaches, the first results in the node being both selected and checked. The second and third result in nodes that are neither selected nor checked. I would like to get a node that is checked but not selected.




Aucun commentaire:

Enregistrer un commentaire