在 Dashcode 列表控制器中设置选择
我的 Dashcode 项目中有一个列表控制器,它从动态源中提取数据。
在我的列表控制器加载其数据后,我想将其选定的索引设置为 0 - 以便显示列表中第一项的信息。我一生都无法弄清楚如何做到这一点。我尝试过:
function load()
{
dashcode.setupParts();
var list = document.getElementById("itemsList");
//list.setSelectionIndexes(0); // nope
//list.selectedIndex = 0; // nope
}
I have a list controller in my Dashcode project, it pulls its data from a dynamic source.
After my list controller has loaded its data I'd like to set it's selected index to 0 - so that information for the first item in the list is shown. I can't for the life of me figure out how to do this. I've tried:
function load()
{
dashcode.setupParts();
var list = document.getElementById("itemsList");
//list.setSelectionIndexes(0); // nope
//list.selectedIndex = 0; // nope
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无需为此编写任何代码。在检查器中编辑列表的属性,然后在属性选项卡中取消选中允许空选择。如果不允许空选择,则在加载列表时将选择列表中的第一项。
No need to write any code for that. Edit the properties for the list in the inspector and uncheck allow empty selection in the attributes tab. With no null selection allowed the first item in the list will be selected when the list loads.
以下是根据名称选择特定项目的示例。对于这个问题,您可以简单地显式设置 0 索引 - 我认为 Vicente 的答案更适合所提出的问题,但这对于根据查询字符串等选择项目很有用。
Here's an example for selecting a specific item based on its name. For this question, you could simply explicitly set the 0 index - I think Vicente's answer is more appropriate for the question asked, but this can be useful for selecting an item based on a querystring, etc.