VSTS Dashboard Widget getWorkItem 可选参数展开

VSTS Dashboard Widget getWorkItem optional parameter expand

我正在编写用于 Work Item Tracking

的 VSTS 仪表板小部件

但是我 运行 在使用 getWorkItem() 函数时遇到了问题。我想获得给定 Epic 下所有 Featuresids(我已经知道史诗ID)。我相信,如果我将 getWorkItem() 的 expand 参数设置为 "All",我将获得所有功能及其各自 ID 的列表。不幸的是,我不知道如何定义扩展参数的 "type" 以及如何将其作为值正确传递给 getWorkItem() 函数。

这是我的代码:

VSS.require(["VSS/Service", "TFS/Dashboards/WidgetHelpers", "TFS/WorkItemTracking/RestClient"],
        function (VSS_Service, WidgetHelpers, TFS_Wit_WebApi) {
            WidgetHelpers.IncludeWidgetStyles();
            VSS.register("myapp", function () {
                var fetchData = function (widgetSettings) {
                    const epicID = 123456;
                    // Get a WIT client to make REST calls to VSTS
                    return VSS_Service.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient).getWorkItem(123456, null, null, All).
                        then(
                            //Successful retrieval of workItems
                            function (workItems) {
                                $('#myText').text(JSON.stringify(workItems));
                                console.log(workItems);
                                // Use the widget helper and return success as Widget Status
                                return WidgetHelpers.WidgetStatusHelper.Success();
                            },
                            function (error) {
                                // Use the widget helper and return failure as Widget Status
                                return WidgetHelpers.WidgetStatusHelper.Failure(error.message);
                            });
                }

这是 expand 的 VSTS 参考 它解释了值可以是什么,但没有说明如何将其传递到 getWorkItem() 函数中。

I would like to set the optional expand parameter of the function to "All" but don't know its type and how to properly define and use it.

基于source code,它是枚举,所以你可以在getWorkItem函数中指定整数(例如4)。

export enum WorkItemExpand {
    None = 0,
    Relations = 1,
    Fields = 2,
    Links = 3,
    All = 4,
}

使用枚举很好,但您也可以传入 'TFS/WorkItemTracking/Contracts' 模块的值。您可以在此处找到参考资料(显示模块路径、'class' 和枚举):

上面的link来自TFS WorkItemTrackingAPI参考,可以在这里找到:

以下是将其添加到代码中的方法:

  1. 声明 'TFS/WorkItemTracking/Contracts' 模块
  2. 将模块传递到回调中(下例中的“_Contracts”)
  3. 根据需要使用“_Contracts”

这是您的代码,已更新为使用合同模块:

VSS.require([
    "VSS/Service", 
    "TFS/Dashboards/WidgetHelpers", 
    "TFS/WorkItemTracking/RestClient",
    "TFS/WorkItemTracking/Contracts"],
    function (VSS_Service, WidgetHelpers, TFS_Wit_WebApi, _Contracts) {

    WidgetHelpers.IncludeWidgetStyles();
    VSS.register("myapp", function () {
        var fetchData = function (widgetSettings) {
            const epicID = 123456;
            // Get a WIT client to make REST calls to VSTS
            return VSS_Service.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient).
                getWorkItem(123456, null, null, _Contracts.WorkItemExpand.All).
                then(
                    //Successful retrieval of workItems
                    function (workItems) {
                        $('#myText').text(JSON.stringify(workItems));
                        console.log(workItems);
                        // Use the widget helper and return success as Widget Status
                        return WidgetHelpers.WidgetStatusHelper.Success();
                    },
                    function (error) {
                        // Use the widget helper and return failure as Widget Status
                        return WidgetHelpers.WidgetStatusHelper.Failure(error.message);
                    });
        }
    });
});

希望对您有所帮助!