【发布时间】:2017-01-04 05:33:44
【问题描述】:
我正在从数据库表中为工具栏上的下拉菜单构建选项,为选项提供与表中索引相同的值,但按选项描述的字母顺序排列。视觉下拉列表很好地排序,但是当我询问所有选项的列表时,它们按 id 排序,即 getAllListOptions() 和 forEachListOption()。除了我自己再次对列表进行排序之外,还有其他方法可以按“正确”顺序查找选项列表以选择列表中的第一个选项吗?
To emphasize, the problem is ID's are not in ascending order when options are sorted by description, however dhtmlx order them internally in ascending order by value instead of by name as they should.即,假设 ID 为 8 的选项位于列表顶部,内部列表中的第一个选项应该是“8”,而不是最小的 ID(在我的情况下为 2)。
网站是 MVC,后端是 MS SQL Server,数据结构,如选项列表,通过 razor 脚本作为 XML 传回。
I.E.获取选项列表的 ajax 调用通过业务层传递到 DAL,DAL 请求按描述排序的对象列表。 razor 脚本然后像这样创建 XML
<item id="tbbOptions" type="buttonSelect" title="@(Messages.Lookup("Config"))" selected="-1" text="@Messages.Lookup("Config_Select")">
@foreach (Analysis oAnalysis in Model.Analysis)
{
if (!string.IsNullOrEmpty(oAnalysis.SecondaryField))
{
<item type="button" id="@(oAnalysis.ID)" img="blueprint.png" imgdis="blueprint.png" text="@string.Format("{0}", oAnalysis.Description)" />
}
else
{
<item type="button" id="@(oAnalysis.ID)" img="blueprint.png" imgdis="blueprint.png" text="@string.Format("{0}", oAnalysis.Description)" />
}
}
</item>
SQL 查询:
public List<Analysis> GetConfig()
{
return UnitOfWork.Database.Fetch<Analysis>("SELECT * FROM [Analysis] ORDER BY [Description]");
}
【问题讨论】:
标签: javascript dhtmlx