I have anchor tag like this
<a href="#" class="btn btn-success order-btn" data-bind="attr:{'data-tiername':$data.tierName, 'data-identifier' : $parent.identifier}, click: $root.setPath.bind($data,$data.tierName, $parent.identifier)">Send values</a>
In the viewmodel
var appViewModel = {
setPath: function (data, tier, identifier) {
alert(data);
alert(tier);
alert(identifier);
},
...........
...........
}
The result is some knockoutjs core code being displayed in alert message (possibly definitions of observable(),dependentObservable() functions and [Object object] which is empty when alerted with JSON.stringify)
why does this work?
data-bind="attr:{'data-tiername':$data.tierName, 'data-identifier' : $parent.identifier}
but not this:
click: $root.setPath.bind($data,$data.tierName, $parent.identifier)
note that tierName is an observable(), identifier is computed()
Where can I find more about bind() ??
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…