0

Visual Studios 在他们的网站上有以下打字稿代码,我试图以此为例:

import RestClient = require("TFS/WorkItemTracking/RestClient");
 // Get an instance of the client
var client = RestClient.getClient();
// Call a method on the client
// e.g. client.getResource(...).then(...);

我拥有的部分javascript代码是:

VSS.init({
        explicitNotifyLoaded: true,
        usePlatformStyles: true
    });
  VSS.require([
      "VSS/Controls",
      "VSS/Controls/Menus",
      "VSS/Controls/Dialogs",
      "VSS/Service",
      "TFS/WorkItemTracking/RestClient",
      "VSS/WebApi/Contracts"],
      function (VSS_Service, TFS_Wit_WebApi) {
          //get the REST client
          var witClient = VSS_Service.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient);
      }
  );

但是,当我这样做时,我收到一条错误消息,指出 VSS_Service.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient) 不是函数。除了 VSS.require(["VSS/Service"] 之外,我还需要初始化 VSS_Service 吗?

4

2 回答 2

1

我制作了 witClient 和外部变量,因此我可以在我的程序中的任何地方使用它,并将控件和网格添加到有效的函数中。

var witClient;
  VSS.init({
        explicitNotifyLoaded: true,
        usePlatformScripts: true, 
        usePlatformStyles: true
    });
  VSS.require([
      "VSS/Controls", "VSS/Controls/Grids",
      "VSS/Service", "TFS/WorkItemTracking/RestClient"],
      function (Controls, Grids, VSS_Service, TFS_Wit_WebApi) {
          //get the REST client
          witClient = VSS_Service;//.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient);
          witClient = witClient.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient);
      }
  );
于 2016-06-23T14:09:17.683 回答
0

看来您的代码是正确的,只是不用RestClient作var,尝试修改

var RestClient = VSS_Service.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient);

var witClient = VSS_Service.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient);

有用的文章:https ://www.visualstudio.com/en-us/docs/integrate/extensions/get-started/node

于 2016-06-23T07:10:56.623 回答