【发布时间】:2018-08-03 15:37:32
【问题描述】:
我正在尝试在自定义 tfs 仪表板小部件的配置页面中添加 Visual Studio Team Services (VSTS) Multivalue Combo Control。我能够让小部件出现,并且可以动态地向它添加值。但我无法“保存”该值。下面是我用来尝试创建和保存此控件值的 Javascript。我从第 34 行的浏览器控制台收到“未捕获的类型错误:无法读取未定义的属性'通知'”的错误(我的多选中的“更改”函数。我已尝试将逻辑放入“加载”函数中这通常是您放置小部件逻辑的地方,但随后我收到一个错误,指出在我的 var multiValueCombo = Controls.create(Combos.Combo, CustomContainer, multiValueOptions); 行中未定义“创建”。
关于当前代码的立场。当我更改控件中的值时,“保存按钮”不会启用。我相信这是由于“通知”功能没有触发。
VSS.require(["TFS/Dashboards/WidgetHelpers", "TFS/DistributedTask/TaskAgentRestClient", "VSS/Controls", "VSS/Controls/Combos"], function (WidgetHelpers, TFS_TaskAgentRestClient, Controls, Combos) {
VSS.register("DeploymentReports.Configuration", function () {
var CustomContainer = $("#custom-combo-container");
//Creating the Multiselect Control
var multiValueOptions = {
type: "multi-value",
width: 250,
source: [
"Ford"],
change: function () {
//What it does when you change the value of the multiselect
var customSettings = { data: JSON.stringify({ iteration: this.getText() }) };
var eventName = WidgetHelpers.WidgetEvent.ConfigurationChange;
var eventArgs = WidgetHelpers.WidgetEvent.Args(customSettings);
widgetConfigurationContext.notify(eventName, eventArgs); //I get an error for this line "Uncaught TypeError: Cannot read property 'notify' of undefined"
}
}
$("<label />").text("Select the supported languages:").appendTo(CustomContainer);
var multiValueCombo = Controls.create(Combos.Combo, CustomContainer, multiValueOptions);
var commandArea = $("<div style='margin:auto' />").appendTo(CustomContainer);
return {
load: function (widgetSettings, widgetConfigurationContext, Controls, Combos) {
//adding items to the multiselect drop down
multiValueOptions.source.push("Volvo");
multiValueOptions.source.push("Jeep");
return WidgetHelpers.WidgetStatusHelper.Success();
},
//Clicking the Save Button
onSave: function() {
var customSettings = {
data: JSON.stringify({
cars: multiValueOptions.getText()
})
};
return WidgetHelpers.WidgetConfigurationSave.Valid(customSettings);
}
}
});
VSS.notifyLoadSucceeded();
});
【问题讨论】:
标签: javascript tfs widget azure-devops