This page描述如何使用 RESTful API
(通过 PostMan
)在 Sitecore9
中检索项目、(直接)子项目和搜索。
它似乎没有说明如何组合这些查询。
我想搜索 path
指定的 item
的 children
。所以,目前,我有这个返回一个项目:
GET https://{{sitecorehost}}/sitecore/api/ssc/aggregate/content/Items('{{sitecorehome}}/banners-tests')?sc_apikey={{sitecore-master-apikey}}
我也有这个返回那个项目的子项目:
GET https://{{sitecorehost}}/sitecore/api/ssc/aggregate/content/Items('{{sitecorehome}}/banners-tests/Subcontent/Image and Texts')/Children?sc_apikey={{sitecore-master-apikey}}
但是,因为子级不是直系子级 - 它们在 /Subcontent/Image and Texts
下两个级别 - 我无法请求它们。是的,我可以搜索它们,但随后任何 项都会返回匹配条件,我只想搜索该特定路径下的项。
我想要一些东西,我想它看起来像这样:
GET https://{{sitecorehost}}/sitecore/api/ssc/aggregate/content/Items?sc_apikey={{sitecore-master-apikey}}&$filter=Name eq 'banner' and Path eq 'banners-tests'
或者也许是这样的:
GET https://{{sitecorehost}}/sitecore/api/ssc/aggregate/content/Items('{{sitecorehome}}/banners-tests')/Children?sc_apikey={{sitecore-master-apikey}}&$filter=Name eq 'banner'
但是这些都不行。
最佳答案
@Matt 我们可以根据项目路径进行过滤。例如,考虑项目路径为:
'sitecore/content/home/tenant1/Subcontent/Image and Texts/neededitem' - 需要的那个
'sitecore/content/home/tenant1/Subcontent/Image and Texts/item1/neededitem/notneededitem' - 我们需要排除的那个
因为“/”不是 Sitecore 项目名称中的有效字符,它表示所需项目的子项。 因此,它可以用作 javascript 中的过滤器。 所以我们可以按“图像和文本”拆分,然后找到项目。 例如,考虑一个结果数组,让我们说具有项目集合的对象是项目,每个项目的项目路径由 Path 表示(比方说,这也可以是其他一些属性)属性
let items = [{
Path: 'sitecore/content/home/tenant1/Subcontent/Image and Texts/neededitem',
anotherProperty: 'text-val1'
}, {
Path: 'sitecore/content/home/tenant1/Subcontent/Image and Texts/item1/neededitem/notneededitem',
anotherProperty: 'text-val2'
}];
const results = items.filter(item => {
const splittedPath = item.Path.split('Image and Texts');
if (splittedPath[1].split("/").length <= 2) {
return item;
}
});
console.log(results);
如果您的 SSC Controller (C#) 是自定义 Controller 并且可以访问 Sitecore 上下文对象或 Sitecore API,则 Item 类的 GetChildren() 方法将仅带来第一级的子级。 我希望这会有所帮助。
关于rest - 搜索与特定名称值匹配的子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59180740/