Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

javascript - 如何在Umbraco 7 Backoffice中获取项目的文档字段值(How do I get document field values for an item in Umbraco 7 backoffice)

I have created a custom Umbraco 7 dashboard.(我创建了一个自定义的Umbraco 7仪表板。)

In it I want to get specific field details from instances of a known type of document type in my Umbraco CMS.(在其中,我想从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.(我已经通过使用entityResource.getChildren(1386, "Document")成功获取了特定类型的所有文档的列表,然后在每个此类文档上调用了entityResource.getById(item.id, "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?(如何使用Umbraco的Angular服务/ API获取此信息?)

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);
                        });
                });
        });
    });
  ask by Pete Stens?nes translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

OK, after much poking around I found the answer;(好吧,经过一番摸索,我找到了答案;)

use the injectable contentResource's getById() method .(使用可注入的contentResource的getById()方法 。) 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;(这将获取内容项的所有详细信息,相比之下,entityResource的getById()只是获取内容树的公共详细信息,而后者的resources方法可为您获取所有内容项的详细信息。) 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.(因此,要总结可注入资源entityResource中的使用方法以获取详细信息的子集,但要获取文档的所有详细信息,请使用可注入的contentResource资源。)

Simple when you read enough of the documentation!(阅读足够的文档就很简单!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...