Reputation: 5665
I have created a custom Umbraco 7 dashboard. In it I want to get specific field details from instances of a known type of document type in my Umbraco CMS.
I have successfully obtained a list of all documents of a specific type by using entityResource.getChildren(1386, "Document")
, and subsequently call entityResource.getById(item.id, "Document")
on each such document. I can see many details for each document instance, but not the data the editor entered when creating it. How do I get this information using the Angular services/API of Umbraco?
Sample of dashboard code:
// 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);
});
});
});
});
Upvotes: 2
Views: 851
Reputation: 5665
OK, after much poking around I found the answer; use the injectable contentResource's getById() method. This gets all the details of a content item, in contrast the entityResource's getById() which just gets common details for a content tree, the latter resources methods gets you all a content items details; entered field data included.
contentResource.getById(item.id)
.then((data) =>
{
//console.log('contentResource.getById data', data);
angular.forEach(data.properties, (property) =>
{
//do something with the document's content...
});
});
So to summarise use methods in the injectable resource entityResource
to get a sub set of details, but to get all details of a document use the injectable contentResource
resource.
Simple when you read enough of the documentation!
Upvotes: 1