Passing the model as argument in the link button click using KO

自古美人都是妖i 提交于 2019-12-23 05:33:11

问题


In this below example I need to pass the model as argument in the link button click (List, range) . how to acheive this

<div data-bind = "foreach:modelList" >
        <div class="BDCRQuery">
            <div class= "Body" > 
                <div>
                    <select id ="SELECT" data-bind="options: Attributes, optionsText: 'AttributeName', optionsValue: 'Id', optionsCaption: 'Select Attribute...',value : SelectedAttribute"></select>
                </div>
                <div>
                    <span>with any of the following values:</span>
                </div>
                <div class="option">
                    <a href="#"  id = "List" class="link">List</a> | <a href="#"  id= "Range" class="link">Range</a>
                </div>
               </div>
    </div>
</div>             

回答1:


luse the $parent and bind keywords

<a data-bind="click: $parent.functionName.bind($parent)" />

$parent will point to the object holding the array of modelList and it will call a function called functionName, bind will ensure that the this keyword is the correct context. The function will have the item clicked as the argument



来源:https://stackoverflow.com/questions/13468524/passing-the-model-as-argument-in-the-link-button-click-using-ko

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!