I have a custom binding for translations:
ko.bindingHandlers.lang = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
Can you not just make your translation a normal function, and then call it from your table row binding?
var translate = function(text)
{
this.lang = [
'text1':'text1 translated'
,'text2':'text2 translated'
];
},
var translatedString = this.lang[text];
return translatedString;
}
};
You could then pass in an extra parameter to the tableRow method to indicate whether you want translation or not:
You could then call this in your table row binding function:
ko.bindingHandlers.tableRow = {
update : function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var text1 = valueAccessor()[2] ? translate(valueAccessor()[0]) : valueAccessor()[0];
var text2 = valueAccessor()[2] ? translate(valueAccessor()[1]) : valueAccessor()[1];
$(element).html("" + text1 + " " + text2 + " ");
}
}
Then you can call it directly from bound elements: