问题
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