[英]How do I get document field values for an item in Umbraco 7 backoffice
我創建了一個自定義的 Umbraco 7 儀表板。 在其中,我想從 Umbraco CMS 中已知類型的文檔類型的實例中獲取特定的字段詳細信息。
我通過使用entityResource.getChildren(1386, "Document")
成功獲取了特定類型的所有文檔的列表,然后在每個此類文檔上調用entityResource.getById(item.id, "Document")
。 我可以看到每個文檔實例的許多詳細信息,但看不到編輯器在創建它時輸入的數據。 如何使用 Umbraco 的 Angular 服務/API 獲取此信息?
儀表板代碼示例:
// get community alerts
entityResource.getChildren(1386, "Document")
.then(function (ent)
{
angular.forEach(ent, function (item)
{
let communityalert = {
umbracoItem: item,
title: '', // I want data from each document to put here
topic: ''
};
entityResource
.getById(item.id, "Document")
.then(function (entity)
{
console.log('entity', entity);
communityalert.title = entity.name;
communityalert.umbracoItem = entity;
entityResource
.getUrl(item.id, "Document")
.then(function (url)
{
communityalert.url = url;
// finally push collected data to VM.
vm.CommunityAlerts.push(communityalert);
});
});
});
});
好吧,經過一番摸索,我找到了答案; 使用可注入的 contentResource 的 getById() 方法。 這將獲取內容項的所有詳細信息,相比之下,entityResource 的 getById() 僅獲取內容樹的公共詳細信息,后者的資源方法為您獲取所有內容項的詳細信息; 包括輸入的字段數據。
contentResource.getById(item.id)
.then((data) =>
{
//console.log('contentResource.getById data', data);
angular.forEach(data.properties, (property) =>
{
//do something with the document's content...
});
});
因此,總結使用可注入資源entityResource
來獲取詳細信息的子集,但要獲取文檔的所有詳細信息,請使用可注入的contentResource
資源。
當您閱讀足夠的文檔時很簡單!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.