Set the selection in the controller list of Danish codes
I have a list controller in my Dashcode project, it fetches data from a dynamic source.
After my list controller has loaded its data, I would like to set it by the selected index to 0 - so that information for the first item in the list is displayed. I canβt figure out for my life how to do this. I tried:
function load()
{
dashcode.setupParts();
var list = document.getElementById("itemsList");
//list.setSelectionIndexes(0); // nope
//list.selectedIndex = 0; // nope
}
+2
a source to share
3 answers
Here's an example of selecting a specific item based on its name. For this question, you can just explicitly specify the index 0 - I think Vicente's answer is more appropriate for the question asked, but it might be useful for selecting an item based on a query, etc.
function load()
{
dashcode.setupParts();
setSelectedItem();
}
function setSelectedItem()
{
var itemSource = dashcode.getDataSource("itemsSource");
var inProgress = itemSource.valueForKey("queryInProgress");
if(inProgress)
{
setTimeout("setSelectedItem()", 200);
}
else
{
var items = itemSource.valueForKeyPath("content.items")
for(i=0;i<items.length;i++)
{
if(items[i].name.toLowerCase() == "specificItemName")
{
document.getElementById("list").object.setSelectionIndexes([i]);
}
}
}
}
0
a source to share