How to open dynamically formed hyperlink as Popup

2019-08-10 20:58发布

问题:

I am forming the hyperlink using knock out. Now i have to open the link as popup. Please find the code snippet below

 <a data-bind="attr: { href:'/Home/TechnicianData?logId=' + $data.LoginId}">
                                More tests...
                            </a>

回答1:

Not really a knockout question, it's an HTML question, you just happen to be using knockout ;)

<a target="_blank" data-bind="attr: { href:'/Home/TechnicianData?logId=' + $data.LoginId}">
   More tests...
</a>


回答2:

In that case, I believe the easiest way is binding the "click" event to a function. Like this

<a href="javascript:void(0);" data-bind="click: $root.myFunction">Link Content</a> 

JS

function YourViewModel() {
   var self = this;
   //...
   self.myFunction = function (data) {
       window.open('/Home/TechnicianData?logId=' + data.LoginId);
   };
};


标签: knockout.js