我有以下按钮:
<button class="btn actionButtonIcon" id="DashboardEdit" data-bind="click: changeButtonText">
<figure>
<img src="../../../Images/NotesPink.png" />
<figcaption data-bind="text: $data.ProcurementbuttonText() ? 'Save': 'Edit'"></figcaption>
</figure>
</button>
我只想在此特定url http://localhost:5595/#scorecard/ec5aa8ed-2798-4e71-b13d-f3e525994538/dashboard/PrefDashBoard
中显示它
请记住,ec5aa8ed-2798-4e71-b13d-f3e525994538
是一个id,它总是在变化,但我希望它显示所有的id,以及例如按钮应该显示在这里,以及http://localhost:5595/#scorecard/2356789-234-234d-g3g3-reg456452/dashboard/PrefDashBoard
,我想隐藏它的地方,这不是网址。我尝试了以下代码,但它似乎不工作:
<script>
$(document).ready(function(){
if(window.location.pathname.match(/\/dashboard/PrefDashBoard))
{
$(".DashboardEdit").show();
}
else
{
$(".DashboardEdit").hide();
}
});
</script>
下面是该按钮的JS:
self.ProcurementbuttonText = ko.observable(false);
self.changeButtonText = function(){
self.ProcurementbuttonText(!self.ProcurementbuttonText())
if (!self.ProcurementbuttonText()){
var data = {
'ScorecardId':ko.observable(localStorage.getItem('scorecardId'))(),
'DashboardConfig':ko.observable(localStorage.getItem('ElementDataWidget'))()
};
PreferentialProcurementDashboardApi.Save(data);
}
}
self.DashboardEdit = ko.computed({
read: function () {
var text = 'Customise your dashboard';
if (!self.EnableScorecardFeatures()) {
text = 'This feature is currently unavailable for this scorecard type';
} else {
if (!self.HasDocumentsRole()) {
text = 'You do not have sufficient rights to access the Supporting Documents view';
}
}
return text;
}
});
2条答案
按热度按时间pkwftd7m1#
我认为您可以利用
visible
绑定来根据您的条件显示/隐藏按钮第一个
llmtgqce2#
如果你已经安装并配置了Durandal的路由器插件,你也可以使用activeInstruction()observable来获取当前路由的信息。然后你可以在你的计算中使用它来检查当前片段是否与你的页面路由匹配。更多信息在这里:http://durandaljs.com/documentation/api#class/Router/property/activeInstruction