umbraco - 无法获取 IContent 的子级
问题描述
我正在尝试获取Children
一个Icontent
对象。
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
意志为 1 。contentService.GetPagedChildren(filialsParent.Id, 1, 100, out totalChildren);
我IEnumerable<IContent> children
的为空,因此(当然)是我的children.Count()
0
可悲的是filialsParent
,它没有.children()
像我希望的那样包含该功能。
有没有办法获得 my 的孩子filialsParent
,是的,它确实有已出版的孩子。
解决方案
我遇到了完全相同的问题。出于测试目的,我删除了所有内容,只有基本必需品。
==> umbraco 8.0.2
确保你有一个父母和几个孩子
// 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);
推荐阅读
- python - 我正在尝试用不同类型的水果训练我的模型
- arcgis-js-api - 使用 wkid 102704 时,ArcGIS 地图显示所有大陆(完全缩小)
- python - 从 Python boto3 对象派生位置信息
- python - 有没有办法让 Telepot 机器人读取来自其他机器人的消息?
- javascript - 如何使 var 输入在事件侦听器函数之外可用?(JS)
- python - 将数据读入 jupyter notebook
- amazon-web-services - 尝试使用 boto3 阻止公共访问时出错
- apache-spark - 如果数据框列颠倒,随机拆分会生成不同的拆分
- bash - 项目根目录的第 N 个子目录中的 bash 脚本如何可靠地知道项目根目录的绝对路径?
- ios - IOS谷歌地图。整个世界地图的多边形