简体   繁体   English

Visual Studio Team Services REST API 与文档不匹配?

[英]Visual Studio Team Services REST API doesn't match documentation?

Can anyone tell me what I'm doing wrong?谁能告诉我我做错了什么? I'm trying to create a custom widget for Microsoft's Team Services dashboards but it doesn't seem to match up with the documentation.我正在尝试为 Microsoft 的团队服务仪表板创建一个自定义小部件,但它似乎与文档不匹配。

All I'm doing is calling a simple API that's suppose to contain a list of existing queries.我所做的只是调用一个简单的 API,该 API 假定包含现有查询列表。 And I'm logging the results in the console.我正在控制台中记录结果。 But the result I logged out have different properties to that of the documentation.但是我注销的结果与文档的属性不同。

According to the .getQueries() API here;根据此处的 .getQueries() API; REST Client APIs . REST 客户端 API It is suppose to return a 'IPromise<Contracts.QueryHierarchyItem[]>' and QueryHierarchyItem contains a list of members listed here;假设返回'IPromise<Contracts.QueryHierarchyItem[]>'并且 QueryHierarchyItem 包含此处列出的成员列表; QueryHierarchyItem 查询层次项

The object I log out looks something like this:我注销的对象看起来像这样:

    Array
    ->Object
    ---> _links
    ------> html
    ---------> href
    ------> self
    ---------> href
    ------> _proto
    ---> createdDate
    ---> hasChildren
    ---> id
    ---> isFolder
    ---> isPublic
    ---> lastModifiedBy
    ------>displayName
    ------>id
    ------>_proto
    ---> lastModifiedDate
    ---> name
    ---> path
    ---> url
    ---> _proto_

And it doesn't have properties such as an array of 'children' or the boolean 'isDeleted' as described in the documentation for QueryHierarchyItem.并且它没有 QueryHierarchyItem 文档中描述的属性,例如'children'数组或布尔值'isDeleted' Why is this the case?为什么会这样? am I misunderstanding something?我误解了什么吗?

By the way.顺便说一句。 Here is the code I'm using:这是我正在使用的代码:

VSS.require(["TFS/Dashboards/WidgetHelpers", "TFS/WorkItemTracking/RestClient"],
        function(WidgetHelpers, TFS_Wit_WebApi) {
            WidgetHelpers.IncludeWidgetStyles();
            VSS.register("HelloWorldWidget2", function() {
                var projectId = VSS.getWebContext().project.id;

                var getQueryInfo = function(widgetSettings) {


                    //******CALL TO REST API*********//
                    return TFS_Wit_WebApi.getClient().getQueries(projectId)
                        .then(function(queries) {

                            console.log(queries);
                            return true;

                        });
                };

                return {
                    load: function(widgetSettings) {
                        // Set your title
                        var $title = $('h2.title');
                        $title.text('Query Details 3');

                        return getQueryInfo(widgetSettings);
                    }
                }
            });
            VSS.notifyLoadSucceeded();
        });

Any help would be much appreciated.任何帮助将不胜感激。

getQueries() has three optional parameters: getQueries() 有三个可选参数:

  • expand: Contracts.QueryExpand.展开:Contracts.QueryExpand。 Optional.可选。
  • depth: number.深度:数量。 Optional.可选。
  • includeDeleted: boolean. includeDeleted:布尔值。 Optional.可选。

By default, the depth is "0" which means it does not include any children objects in the query/folder.默认情况下,深度为“0”,这意味着它不包括查询/文件夹中的任何子对象。 So it will be blank by default.所以默认情况下它将是空白的。 And the maximum depth you can query is 2. Try to add these optional parameters to see if you can get the result you want.并且你可以查询的最大深度是2。尝试添加这些可选参数,看看你是否能得到你想要的结果。

For the default value of the optional parameters, please refer to this link for details: Get a list of queries .可选参数的默认值请参考这个链接: 获取查询列表

Because I haven't found an answer either, I played with this tonight and did get the query to return all the existing queries with the below code.因为我也没有找到答案,所以我今晚玩了这个,确实得到了使用以下代码返回所有现有查询的查询。 The 3rd parameter(depth) is something to play with, I don't know if it breaks if you put "5" for instance, but only have 3 levels of children, etc.第三个参数(深度)是可以玩的,我不知道如果你输入“5”它是否会中断,但只有 3 个级别的孩子,等等。

The Contracts module is needed in the "VSS.require" line - documentation is lacking years into this... “VSS.require”行中需要 Contracts 模块 - 文档在这方面缺乏多年......

VSS.require(["TFS/Dashboards/WidgetHelpers", "TFS/WorkItemTracking/RestClient", "TFS/WorkItemTracking/Contracts"],
    function(WidgetHelpers, TFS_Wit_WebApi, contracts) {
        WidgetHelpers.IncludeWidgetStyles();
        VSS.register("HelloWorldWidget2", function() {
            var projectId = VSS.getWebContext().project.id;
            var getQueryInfo = function(widgetSettings) {

                //******CALL TO REST API*********//
                return TFS_Wit_WebApi.getClient().getQueries(projectId,contracts.All,2,false)
                    .then(
                            function (queries) {
                                console.log(JSON.stringify(queries));
                                return true;
                            });
            };

            return {
                load: function(widgetSettings) {
                    // Set your title
                    var $title = $('h2.title');
                    $title.text('Query Details 3');

                    return getQueryInfo(widgetSettings);
                }
            }
        });
        VSS.notifyLoadSucceeded();
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio Team Services Rest API未经授权的客户端错误 - Visual Studio Team Services Rest API unauthorized_client error 在Visual Studio Team Services上构建Cordova项目时,构建失败 - Build fails when building Cordova project on Visual Studio Team Services Visual Studio Team Services / SonarQube:将.trx / .coverage文件转换为LCOV吗? - Visual Studio Team Services / SonarQube: Converting a .trx/.coverage file to a LCOV? Visual Studio 代码弹窗文档 API - Visual studio code popup documentation API forEach函数与文档不匹配 - forEach Function doesn't match documentation 是否可以运行Visual Studio Team Services Build中的端到端测试? - Can end-to-end tests in Visual Studio Team Services Build be run? Visual Studio 2013 Javascript无法识别“ &lt;%=%&gt;”吗? - Visual Studio 2013 Javascript doesn't recognize '<%= %>'? Visual Studio IDE无法识别Javascript中的EJS变量 - Visual Studio IDE Doesn't Recognize EJS Variable in Javascript Visual Studio无法识别导入的npm包? - Visual Studio doesn't recognise imported npm package? 为什么Visual Studio intellisense不显示XMLHttpRequest对象方法? - Why Visual Studio intellisense doesn't show XMLHttpRequest objects methods?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM