3

我在 sitefinity 中有一个返回类别列表的函数。

//return list of categories
    private IList<ICategory> GetCategoryDataSource() {

        var cntManager = new ContentManager(CaseStudyManager.DefaultContentProvider);
        IList allCategories = cntManager.GetCategories();
        List<ICategory> filteredList = new List<ICategory>();
        foreach (ICategory category in allCategories) {

            filteredList.Add(category);

        }
        return filteredList;
    }

我想知道的是如何对这个列表进行排序。

据我所知,Sitefinity 中的类别只是一个字符串,没有与类别关联的其他字段。因此,除了为每个类别附加一个数字之外,我没有什么可以对类别进行排序的,例如:

1 - Legal
2 - Financial
3 - Property

当这些类别显示在网站上时,我至少可以修剪我需要的部分。

任何人都可以帮助排序吗?

谢谢艾尔

4

2 回答 2

1

使用IComparer 接口

于 2010-10-26T16:31:29.563 回答
0

如果你像你提到的那样命名它们,带有前缀,你可以这样做:

001|xxxxxxx

002|djskdjskd

003|sdkdsajdaks

foreach (ICategory category in allCategories) 
{              
    filteredList.Add(category.SubString(4);          
} 
于 2011-02-25T13:24:54.563 回答