一把umbraco API:试图获得该文件的数据类型为给定的站点节点 [英] umbraco API: trying to get the document type data for a given site node

查看:176
本文介绍了一把umbraco API:试图获得该文件的数据类型为给定的站点节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想获得有关如何从一把umbraco通过API方法来检索数据的一些观点。我相信,我们使用的是一把umbraco 4.9.x。

Just trying to get some perspective about how to retrieve data from umbraco via the API method. I believe we are using umbraco 4.9.x.

基本上有一个名为DiaryEventItems数据类型,我用下面的code访问此:

Basically there is a data type called DiaryEventItems, and I use the following code to access this:

// Get the ID of the data type
DocumentType DocTypeDiaryEvents = DocumentType.GetByAlias("DiaryEventItems");

// Loop through those items using a foreach at present
foreach (Document DiaryEvent in Document.GetDocumentsOfDocumentType(DocTypeDiaryEvents.Id))
{
    // Do whatever I need to
}

所以这个工作得很好。我找回了采集/DiaryEventItems行,但我从课程的一把umbraco实例..即对于所有站点的所有DiaryEventItems。所以,很显然有方法来获取网站根目录节点ID,也许工作在树中获得实际的文档类型我需要的,但有没有这样做的一些方法类似于上面code?

So this works well.. I get back the collection/rows of "DiaryEventItems", however I get ALL DiaryEventItems from the umbraco instance of course.. i.e. for all sites. So obviously there are methods to get the site root node ID and perhaps work down the tree to get the actual document type I need, however is there some way of doing this which is similar to the above code?

任何帮助AP preciated感谢!

Any help appreciated thanks!

推荐答案

您可以尝试以下仅发布节点的功能:

you can try following function for only Published node:

// this is variable to retrieve Node list
private static List<Node> listNode = new List<Node>();

public static List<Node> GetDescendantOrSelfNodeList(Node node, string nodeTypeAlias)
{
    if (node.NodeTypeAlias == nodeTypeAlias)
        listNode.Add(node);

    foreach (Node childNode in node.Children)
    {
        GetDescendantOrSelfNodeList(childNode, nodeTypeAlias);
    }

    return listNode;
}

现在你可以如下调用该函数在code:

now you can call that function in your code as below:

// 1234 would be root node id
Node rootNode = new Node(1234)

// we are passing root node so that it can search through nodes with alias as DiaryEventItems
List<Node> diaryEventItems = GetDescendantOrSelfNodeList(rootNode, "DiaryEventItems");

我希望这会有所帮助,
如果你在寻找未发表的节点与文档及其不同的,并会采取一点的时间对我来说,但如果你想未发表的节点只那么我会做到这一点稍后。

I hope this would help, if you looking for unpublished node with Document and its different and will be taking little bit time for me but if you want unpublished node only then i'll do that bit later.

这篇关于一把umbraco API:试图获得该文件的数据类型为给定的站点节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆