[英]In knockout data-bind attr bind not working?
I have a problem When clicking link( tag).it contains data-bind,by using attr binding i am giving the url,and at the same time using click binding My problem is click binding is working but not redirect the url by attr binding . 我有一个问题,当单击link(tag)时,它包含数据绑定,通过使用attr绑定,我提供了url,同时使用单击绑定,我的问题是单击绑定有效,但无法通过attr绑定重定向url 。 I try this code..
我尝试这段代码。
viewModel.printbill = function () {
var dta = ko.utils.arrayFilter(viewModel.Bills(), function (item) {
return item.BillID == viewModel.BillID();
});
if (dta != null) {
var data = {
List: dta
}
localStorage.setItem('SelectedBill', JSON.stringify(data));
}
};
<a target="_blank" title="" data-bind='attr: {href:"@Href("~/billing/BillPrint") "},click:printbill'>
when clicking this link i have a click binding:printBill,which is used to select a specific id from the button clik and map into localstorage ...all things are going good..but ..i cant redirect the screen to another tab. <a target="_blank" title="" data-bind='attr: {href:"@Href("~/billing/BillPrint") "},click:printbill'>
单击此链接时,我具有单击绑定:printBill,用于从按钮clik中选择一个特定的ID并映射到本地存储中…一切都很好。但是..i无法将屏幕重定向到另一个选项卡。
If you have both a click
binding and an href on a link then you need to return true from the binding for the href to be followed - think of it as being able to cancel the click (and therefore the navigation). 如果您同时具有
click
绑定和链接上的href,则需要从绑定中返回true,以便遵循的href-将其视为能够取消点击(因此取消导航)。
viewModel.printbill = function () {
var dta = ko.utils.arrayFilter(viewModel.Bills(), function (item) {
return item.BillID == viewModel.BillID();
});
if (dta != null) {
var data = {
List: dta
}
localStorage.setItem('SelectedBill', JSON.stringify(data));
}
return true; // <---- here
};
而不是使用链接使用按钮来重定向并单击
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.