无法获取 IContent 的子项
Unable to get children of IContent
我正在尝试获取 Icontent
对象的 Children
。
IContent filialsParent = cs.GetById(filialParrentId);
if (filialsParent != null)
{
IContentService contentService = Umbraco.Core.Composing.Current.Services.ContentService;
bool hasChildren = contentService.HasChildren(filialsParent.Id);
long totalChildren;
IEnumerable<IContent> children = contentService.GetPagedChildren(filialsParent.Id, 1, 100, out totalChildren);
foreach (var child in children)
{
context.WriteLine(string.Format("child: {0}", child.Name));
}
context.WriteLine(string.Format("Children found:({0}) in: {1}", children.Count(), filialParrentId));
}
如果我调试代码,我会得到以下信息。
我的 long totalChildren
行 contentService.GetPagedChildren(filialsParent.Id, 1, 100, out totalChildren);
运行后将为 1。
我的 IEnumerable<IContent> children
是空的,因此(当然)是我的 children.Count()
0
遗憾的是 filialsParent
没有包含我希望的功能 .children()
。
有没有办法获取我的 filialsParent
的子项,是的,它确实有已发布的子项。
我遇到了完全相同的问题。出于测试目的,我删除了所有内容。只有最基本的东西。
==> umbraco 8.0.2
确保你有一个 parent 和几个孩子
// For testing purposes hardcode your parent Id
var contentId = [ID];
// SET for returning total records
long totalChildren;
// int id ==> You even could hardcode your first param (contentID in here)
// long pageIndex ==> SET your index to 0 ==> first indexpage starts at 0 and not 1 ==> if you set this to 1 and the Pagesize = 100 and you have only 99 childeren you wil wil get null because we are requesting the second page
// int pageSize ==> We need max 10 childeren
// out long totalChildren
// IQuery<IContent> filter = null ==> not used
// Ordering ordering = null ==> not used
IEnumerable<IContent> children = Services.ContentService.GetPagedChildren(contentId, 0, 10, out totalChildren);
我正在尝试获取 Icontent
对象的 Children
。
IContent filialsParent = cs.GetById(filialParrentId);
if (filialsParent != null)
{
IContentService contentService = Umbraco.Core.Composing.Current.Services.ContentService;
bool hasChildren = contentService.HasChildren(filialsParent.Id);
long totalChildren;
IEnumerable<IContent> children = contentService.GetPagedChildren(filialsParent.Id, 1, 100, out totalChildren);
foreach (var child in children)
{
context.WriteLine(string.Format("child: {0}", child.Name));
}
context.WriteLine(string.Format("Children found:({0}) in: {1}", children.Count(), filialParrentId));
}
如果我调试代码,我会得到以下信息。
我的 long totalChildren
行 contentService.GetPagedChildren(filialsParent.Id, 1, 100, out totalChildren);
运行后将为 1。
我的 IEnumerable<IContent> children
是空的,因此(当然)是我的 children.Count()
0
遗憾的是 filialsParent
没有包含我希望的功能 .children()
。
有没有办法获取我的 filialsParent
的子项,是的,它确实有已发布的子项。
我遇到了完全相同的问题。出于测试目的,我删除了所有内容。只有最基本的东西。
==> umbraco 8.0.2
确保你有一个 parent 和几个孩子
// For testing purposes hardcode your parent Id
var contentId = [ID];
// SET for returning total records
long totalChildren;
// int id ==> You even could hardcode your first param (contentID in here)
// long pageIndex ==> SET your index to 0 ==> first indexpage starts at 0 and not 1 ==> if you set this to 1 and the Pagesize = 100 and you have only 99 childeren you wil wil get null because we are requesting the second page
// int pageSize ==> We need max 10 childeren
// out long totalChildren
// IQuery<IContent> filter = null ==> not used
// Ordering ordering = null ==> not used
IEnumerable<IContent> children = Services.ContentService.GetPagedChildren(contentId, 0, 10, out totalChildren);