Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure devops 如何在VSTS扩展中使数据存储成为项目独有的?_Azure Devops_Azure Devops Extensions - Fatal编程技术网

Azure devops 如何在VSTS扩展中使数据存储成为项目独有的?

Azure devops 如何在VSTS扩展中使数据存储成为项目独有的?,azure-devops,azure-devops-extensions,Azure Devops,Azure Devops Extensions,这就是我们在VSTS扩展中访问数据存储的方式。 MyCollection2是我们正在使用的存储的名称。 然而,这并不是该项目独有的。当我尝试从同一组织内的另一个项目访问中心扩展时,仍然可以看到数据 我尝试根据我访问的项目动态命名集合,但没有明确的方法在扩展端获取项目名称 如何使数据存储对同一组织内的项目唯一???您可以从中获取项目名称。然后将DocumentId值设置为ProjectName: VSS.getService(VSS.ServiceIds.ExtensionData)

这就是我们在VSTS扩展中访问数据存储的方式。
MyCollection2
是我们正在使用的存储的名称。 然而,这并不是该项目独有的。当我尝试从同一组织内的另一个项目访问中心扩展时,仍然可以看到数据

我尝试根据我访问的项目动态命名集合,但没有明确的方法在扩展端获取项目名称


如何使数据存储对同一组织内的项目唯一???

您可以从中获取项目名称。然后将DocumentId值设置为ProjectName:

    VSS.getService(VSS.ServiceIds.ExtensionData)
    // the callback on the next line returns a promise, which the JavaScript engine will follow, so you don't need to nest the next `then`
        .then((dataService) => dataService.getDocuments('MyCollection2'))
        .then((docs) => { ...
之后,检索设置值:

// Get data service
    VSS.getService(VSS.ServiceIds.ExtensionData).then(function(dataService) {
        // Set value (default is project collection scope)
        dataService.setValue("ProjectName", "DocumentId").then(function(value) {
            console.log("Key value is " + value);
        });
    });
最后,当您从DocumentId获取文档时,它将从项目中获取:

// Get data service
    VSS.getService(VSS.ServiceIds.ExtensionData).then(function(dataService) {
        // Get value in user scope
        dataService.getValue("ProjectName").then(function(value) {
            console.log("User scoped key value is " + value);
        });
    });

事实上,我通过承诺来解决这个问题

// Get data service
    VSS.getService(VSS.ServiceIds.ExtensionData).then(function(dataService) {
        // Get document by id
        dataService.getDocument("MyCollection", "DocumentId").then(function(doc) {
            // Assuming document has a property named foo
            console.log("Doc foo: " + doc.foo); 
        });
    });
然后


只要VSS准备好获取,就会返回web上下文。

谢谢您的回答。这是有道理的,但每当我使用
VSS.getWebContext()
,它都会给我一个
未定义的
。我在
VSS.init()之后做了
我还尝试使用
\uu vssPageContext
。当我试图从VSTS页面控制台它时,这是可以访问的,但是当我把它放在像
console.log(\uu vssPageContext)
这样的代码中时,它会说
undefined
。把它放在
vss.ready
vss.ready(函数(){vss.GetWebContext})?Dong仍然表示未定义。奇怪的是,当我将它放入onclick函数时,它就工作了。但是我想在加载时使用它。@Dawn17在哪里使用扩展名并调用getWebContext()?例如构建摘要或工作中心等等?
    // Sets unique data storage name for each project
    function setDBName() {
        return new Promise(function(resolve, reject) {

                VSS.ready(function(){
                    let web = VSS.getWebContext();
                    resolve(web);
                })
        })
    }
    setDBName()
        .then(function(res){
            console.log('res', res)
        }
        .catch(function(err){
            console.log('err', err)
        }