1

我试图从 ContentItem 中检索分类术语的完整列表,执行如下操作:

var product = Services.ContentManager.Get<ContentItem>(33);

foreach (var term in product.TermsPart.Terms.Where(x => x.Field == "MyIndex"))
{
    ...
}

有人能帮我吗?

我读到它是可能的,使用动态来做到这一点:

dynamic product = Services.ContentManager.Get<ContentItem>(33);

foreach (var term in product.MyIndex.Terms)
{
    ...
}

但我找不到正确的语法!

4

1 回答 1

3

最好的方法是使用 ITaxonomyService ( http://orchardtaxonomies.codeplex.com/SourceControl/latest#Services/ITaxonomyService.cs )

将其注入您的类的构造函数(控制器、依赖项或其他):

  //Note that I didn't try this code
    public SomeController(ITaxonomyService taxonomyService){
         var product = Services.ContentManager.Get<ContentItem>(33);
         var terms = taxonomyService.GetTermsForContentItem(product.Id); //Or just 33

   }
于 2013-11-20T19:11:43.010 回答