简体   繁体   English

淘汰赛数据绑定点击

[英]Knockout data-bind click

I am trying to understand a button on a third party site my company uses. 我试图了解我公司使用的第三方网站上的按钮。 The button signs up a user for a class. 该按钮为用户注册课程。

<a class="btn btn-large btn-blue" href="javascript:void(0);" 
        data-bind="click: $root.clickAction.bind($data, ActionType)">
        <span data-bind="text: Title">Sign up</span></a>

I was hoping to provide this button on a page in our company internal website, but I am not familiar with Knockout. 我希望在我们公司内部网站的页面上提供此按钮,但是我对淘汰赛并不熟悉。 I understand a GET request so if that button did something like this then I would get it. 我了解GET请求,因此如果该按钮执行了类似的操作,那么我会得到它。

thirdparty.com?method=register&classId=1234&userId=abcde

Is it even feasible to turn that knockout button into a GET or to somehow provide the signup mechanism on our internal sites to this 3rd party site? 将淘汰按钮变成GET还是以某种方式在我们内部站点上向第三方站点提供注册机制,是否可行? I can certainly paste more of the source as I'm sure more is needed. 我当然可以粘贴更多的源代码,因为我确定需要更多的源代码。

I've tried using Firefox developer tools and viewing network traffic. 我尝试使用Firefox开发人员工具并查看网络流量。 I don't want to keep spinning my wheels if this isn't doable. 如果这不可行,我不想继续转动轮子。

Knockout provides several objects to access different levels of context and $root is of them. 淘汰赛提供了几个对象来访问不同级别的上下文,$ root是其中的对象。 The $root object represents the main view model object in the root context. $ root对象表示根上下文中的主视图模型对象。 For instance, if your HTML element is inside another binding context, such as inside a foreach, and you want to use a root view model's method in each iteration: 例如,如果您的HTML元素在另一个绑定上下文中,例如在foreach中,并且您希望在每次迭代中使用根视图模型的方法:

  var ViewModel = function() { this.actionTypes = ko.observableArray([ { ActionType: "Type A", Title: "Title A"}, { ActionType: "Type B", Title: "Title B"}, { ActionType: "Type C", Title: "Title C"}]); this.clickAction = function(action) { // your ajax request would go here alert(action); } }; ko.applyBindings(new ViewModel()); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script> <div data-bind="foreach: actionTypes"> <a class="btn btn-large btn-blue" href="javascript:void(0);" data-bind="click: $root.clickAction.bind($data, ActionType)"> <span data-bind="text: Title">Sign up</span> </a> <div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM