состояние следующее: у меня есть страница бритвы и нокаут. Посмотреть модель У меня есть кнопка, подобная этой:
<button class="btn btn-primary btn-icon fill d-prt-none" data-bind="visible:$root.bookable,attr: { id: 'addToBasket-btn_'+$index(), }"><i class="mz-shop mr-1" aria-hidden="true"></i><span>Book</span></button>
и модель вида с нокаутом выглядит примерно так:
export default class EventDetails {
constructor(options, eventKey) {
this.Options = Object.assign({}, options);
this.Event = ko.observable();
this.EventAvalibality = ko.observable(null);
this.basketUtil = new BasketTitleUtil(options);
this.basketUtil.maxAmount = 10;
if (options.loadNotepads) {
this.notepads = new NotepadsViewModel({
apiBaseUrl: options.apiBaseUrl,
apiToken: options.apiToken
});
} else {
this.notepads = {};
}
// computed values
this.showLoading = ko.computed(function() {
return this.EventAvalibality() == null;
}, this);
this.avaIndecator = ko.computed(function() {
if (this.EventAvalibality()) {
return this.MapAvailabilityIndectror(this.EventAvalibality().EventAvailablility());
}
}, this);
this.bookable = ko.computed(function() {
let result = false;
if (this.EventAvalibality()) {
result = this.EventAvalibality().EventAvailablility() == 0 || this.EventAvalibality().EventAvailablility() == 1;
}
return result;
}, this);
this.avalibialityLoaded = ko.computed(function() {
return this.EventAvalibality() != null;
}, this);
this.maxSeats = ko.computed(function() {
if (this.avalibialityLoaded()) {
if (this.EventAvalibality().FreePlaces() > 10)
return 10;
else
return this.EventAvalibality().FreePlaces();
}
}, this);
this.Init(eventKey);
}
formatCurrency = (amount) => {
console.log(amount);
var formatOptiopns = {
'decimal': ',',
'grouping': '.',
'fraction': 2,
'prefix': '',
'suffix': ''
};
return CurrencyFormatter.format(parseFloat(amount), formatOptiopns)
}
CheckAvalibality = (e) => {
$.ajax({
url: this.Options.apiBaseUrl + "/api/products/events/availability/" + this.Event().EventKey(), // counter IE hard caching
headers: {
'Authorization': 'Bearer' + this.Options.apiToken
},
beforeSend: () => {
this.ShowBtnLoading($("#check-availability"), "white");
},
success: response => {
this.RemoveBtnLoading($("#check-availability"), "<i class='mz-shop mr-1' aria-hidden='true'></i><span> Verfügbarkeit abrufen");
let vm = ko.mapping.fromJS(response);
this.EventAvalibality(vm);
}
});
}
MapAvailabilityIndectror = avaCode => {
let result = {};
if (avaCode < 2)
result["av-" + avaCode] = true;
else
result["av-2"] = true;
return result;
}
Init(eventKey) {
$.ajax({
url: this.Options.apiBaseUrl + "/api/search/details/event/" + eventKey + '?v=' + Date.now(), // counter IE hard caching
headers: {
'Authorization': 'Bearer' + this.Options.apiToken
},
success: response => {
let vm = ko.mapping.fromJS(response);
// ------------------------------------------------------------------------
// MOCK
vm.MANZ_Contact = ko.mapping.fromJS({
"FirstName": "Barbara",
"LastName": "Krenn",
"TitlePrefix": "Mag.",
"TitleSuffix": null,
"Phone": "+43 1 xxxxx",
"EMail": "bkr@manz.at"
});
vm.Availability = ko.mapping.fromJS({
"AvailabilityState": null,
"AvailabilityText": "Verfügbarkeit unbekannt"
});
// ------------------------------------------------------------------------
if (vm.Prices) {
vm.Prices = {
StandardPrice: vm.Prices().find(item => item.Type() === 'Voll'),
ReducedPrice: vm.Prices().find(item => item.Type() === 'Reduziert'),
PriceOptions: vm.Prices().filter(item => item.Type() === 'Spezial')
};
for (let key in vm.Prices) {
if ($.isArray(vm.Prices[key])) {
vm.Prices[key].forEach(price => this.CreatePriceSummary(price));
} else {
this.CreatePriceSummary(vm.Prices[key]);
}
}
}
if (vm.Moderators) {
for (let moderator of Common.parseFunction(vm.Moderators)) {
moderator.FullName = ko.computed(() => [
Common.parseFunction(moderator.Salutation_Prefix),
Common.parseFunction(moderator.FirstName),
Common.parseFunction(moderator.LastName),
Common.parseFunction(moderator.Salutation_Suffix)
].join(' ').trim());
moderator.ImageUrl(Common.parseFunction(moderator.ImageUrl) || '/images/noPortrait.svg');
moderator.Description(Common.parseFunction(moderator.Description) || '<strong>' + Common.parseFunction(moderator.FullName) + '</strong> ist lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.')
}
}
vm.BasketAmount = ko.observable(1);
vm.CoverLink = ko.observable(null);
vm.CoverThumbnails = ko.observable(null);
this.Event(vm);
$("#check-availability").click();
}
});
}
CreatePriceSummary(price) {
return price ? price.PriceSummary = ko.computed(() => Common.currency.format(Common.parseFunction(price.Amount)).replace('EUR', '')) : '';
}
ShowErrorDetails(elem) {
let msg = '<ul><li class="error">' + elem.OnixValidationErrors().join('</li><li class="error">') + '</li></ul>';
if (elem.OnixErrors()) {
msg = '<ul><li class="error">' + $.map(elem.OnixErrors(), function(error) {
return error.Error() + ' <strong>(' + error.LineNumber() + ':' + error.LinePosition() + ')</strong>';
}).join('</li><li class="error">') + '</li></ul>';
}
new Dialog('.modal', {
type: 'error',
size: 'large',
title: "ONIX-Fehler Details",
message: msg
});
}
ShowMediaFile(item, evt) {
new Dialog('#reader', {
size: 'xlarge',
remove: false
});
var frame = "";
try {
var Link = Common.parseFunction(item.Url);
frame = !/(?:jpe?g|gif|tiff)/.test(Link) ? '<object type="application/pdf" data="' + Link + '" style="width: 100%; height: 850px; max-height: 100%;" />' : '<img class="img-fluid" src="' + Link + '" />';
if (/(?:jpe?g|gif|tiff)/.test(Link)) {
$('#readerWidget').css({
overflow: 'auto'
});
}
$('#readerWidget').html($(frame));
} catch (e) {
console.log(e);
}
}
ShowBtnLoading(btn, color) {
var currentWidth = btn.css("width");
var currentHeight = btn.css("height");
// disable button
btn.attr("disabled", true);
// show loading
btn.text("");
btn.css("height", currentHeight);
btn.css("width", currentWidth);
btn.css("background-position", "50% 50%");
btn.css("background-repeat", "no-repeat");
btn.css("background-size", "24px");
switch (color.toLowerCase()) {
case "white":
btn.css("background-image", "url(/icons/loading-spinner.svg)");
break;
case "red":
btn.css("background-image", "url(/icons/loading-spinner.svg)");
break;
}
}
RemoveBtnLoading(btn, txt) {
btn.css("background-image", "none");
btn.attr("disabled", false);
btn.html(txt);
}
}
window.EventDetails = EventDetails;
я хочу достичь, когда я нажимаю на кнопку, которую я перенаправил на другой метод действия, я попробовал что-то подобное:
<a class="btn btn-primary btn-icon fill d-prt-none" data-bind="visible:$root.bookable,attr: { href:'/checkout/events/' + eventKey + '?seats=' + BasketAmount, id: 'addToBasket-btn_'+$index(), }"><i class="mz-shop mr-1" aria-hidden="true"></i><span>Book</span></a>
но это не работает, любая помощь будет оценена и спасибо заранее.