Currently, there is no way to reuse a single method of a model and execute different logic based on additional data related to the specific element.
Before the CSP improvements in R1 2023, an unsupported workaround was configuring the method along with the arguments that were evaluated and accessible from the method itself.
Example of the unsupported approach:
<div id="test">
<p data-bind="text: spanLabel('test')" ></p>
<p data-bind="text: spanLabel('another test')"></p>
</div>
<script>
var viewModel = kendo.observable({
spanLabel: function(args){
return "spanLabel executed, args: "+ args
},
});
kendo.bind($("#test"), viewModel);
</script>
Improvement suggestion
Allow the model methods to have access to the reference element. That would enable the internal method logic to get additional data based on the element and achieve the same functionality as the unsupported workaround approach.
Example of the desired functionality:
<div id="test">
<p data-bind="text: spanLabel" data-span-label="test"></p>
<p data-bind="text: spanLabel" data-span-label="another test"></p>
</div>
<script>
var viewModel = kendo.observable({
spanLabel: function(args) {
let element = args.referenceElement;
let spanLabelArgs = element.attr("data-span-label")
return "spanLabel executed, args: " + spanLabelArgs
},
});
kendo.bind($("#test"), viewModel);
</script>