2016-04-20 83 views
0

这是当前的代码:如何循环关系中的项目?

Class %Utcov.Test Extends %RegisteredObject 
{ 

ClassMethod listClasses(ns As %String, projectName As %String) 
{ 
    // Switch namespaces to the new one 
    new $namespace 
    set $namespace = ns 

    // Grab our project, by name; fail otherwise 
    // TODO: failing is CRUDE at this point... 
    #dim project as %Studio.Project 
    #dim status as %Status 

    // TODO: note sure what the "concurrency" parameter is; leave the default 
    // which is -1 
    set project = ##class(%Studio.Project).%OpenId(projectName, /* default */, .status) 

    if ('status) { 
     write "Argh; failed to load", ! 
     halt // meh... Ugly, f*ing ugly 
    } 

    w project.Items 
} 

ClassMethod main() 
{ 
    do ..listClasses("USER", "cache-tort-git") 
} 

} 

首先第一件事情:我知道这些代码很烂......但是,这是学习曲线,我最终会做的更好。我想在这里解决的问题这条线:

w project.Items 

在控制台,它目前打印:

[email protected]%Library.RelationshiptObject 

,但我想这样做当然是通过这些对象,以循环WH根据文件,ich是%Studio.ProjectItem的“实例”。

如何循环浏览这些内容? WRITE不会削减它,事实上,我从一开始就猜测它不会......我只是无法弄清楚这是如何在ObjectScript中完成的:/

回答

2

当你用w project.Items写的对象时, [email protected]%Library.RelationshiptObject,这个字符串可能有助于理解我们得到的对象,在这种情况下,它是类%Library.RelationshiptObject的对象,当您在documentation中打开此类时,您可能会发现一些可以帮助您的方法。
Here你可以找到一些例子,如何处理关系,以对象的方式和SQL。

+0

我偶然发现了这个页面,所以现在我有了对象列表。有一个类型为'PKG'的对象似乎是我想要的...现在我需要能够列出该对象中的文件... – fge

0
Set tKey = "" 
For { 
    ;tItem will be the first item in your list which will be ordered by OREF 
    Set tItem = project.Items.GetNext(.tKey) 
    Quit:(tKey = "") 
    ;Do whatever you want with tItem 
} 
+0

请使用适当的代码格式清理您的答案。 – Shawn