I'm currently making a a C# MVC application, where I'm using jsTree for one of the UI elements. I use checkboxes with the jsTree. I can already retrieve all selected values and pass them to my controller for it to do its thing, no problem there.
But I'm having trouble with filling the jsTree up on loading the webpage. Currently I have this code:
@foreach (var obj in listServers)
{
<li id="root_@obj.DBServerID">
@obj.DBServerName
<ul>
@{
System.Data.DataSet myDS = Model.findDataBasesByServerID(obj.DBServerID);
foreach (System.Data.DataRow row in myDS.Tables[0].Rows)
{
if (dbRepos.isThisDatabaseSelectedForThisUser(Model.LoginID, obj.DBServerID, nameOfDB) == true) //true -> user has selected this earlier and needs to be selected
{
<li class="jstree-clicked get_checked" id="@(obj.DBServerID)_@nameOfDB">@nameOfDB </li>
}
else //false -> user hasn't selected this earlier. Make a normal, unchecked checkbox
{
<li id="@(obj.DBServerID)_@nameOfDB">@nameOfDB </li>
}
}
}
</ul>
</li>
}
The code only works partially. Naturally my jsTree gets made nicely, but the default values don't get checked. The problem isn't with my isThisDatabaseSelectedForThisUser method, cause I debugged and tested it. It works as intended. I'm guessing there's something wrong with the class of the < li > element, but I can't figure out what. The get_checked attribute is given at runtime to indicate the checkbox has been clicked and thus selected. Please note that I'm working with checkbox values of the jsTree here, the selection of the text of the < li > elements aren't important.
Aucun commentaire:
Enregistrer un commentaire