0

APIメソッドを介してumbracoからデータを取得する方法についての見通しを得ようとしているだけです。umbraco4.9.xを使用していると思います。

基本的に、DiaryEventItemsと呼ばれるデータ型があり、これにアクセスするには次のコードを使用します。

// 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を取得し、ツリーを下に移動して必要な実際のドキュメントタイプを取得する方法がありますが、上記のコードと同様の方法はありますか?

助けてくれてありがとう!

4

1 に答える 1

2

公開されたノードに対してのみ、次の機能を試すことができます。

// 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;
}

これで、次のようにコードでその関数を呼び出すことができます。

// 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");

Documentとその別の未公開ノードを探していて、少し時間がかかる場合は、これが役立つことを願っていますが、未公開ノードのみが必要な場合は、少し後で行います。

于 2012-09-27T13:40:20.860 に答える