Hi,
We are moving our javascript files to typescript for a number of reasons, but one issue that I have is the calling of this.dataitem whilst inside a class, because the this object refers to the class rather than the calling object.
The current code that was inside the partial is
function onSelect(e) {
var dataItem = this.dataItem(e.item.index());
window.document.getElementById($('summary').val()).innerHTML = dataItem.Summary;
window.document.getElementsByName($('#id').val())[0].value = dataItem.Id;
}
the code in the typescript class is
namespace myNamespace{
export class myClassObject
... other methods
onSelect(e) {
var dataItem = this.dataItem(e.item.index()); // This is the line that I am having issue with because of 'this'
(window as any).document.getElementById(this.spnSummary).innerHTML = dataItem.Summary;
(window as any).document.getElementsByName(this.nameOfIdField)[0].value = dataItem.Id;
}
}
}
The Razor that is calling this is (minus bits that are not necessary to this question
@(Html.Kendo().AutoComplete()
.Name(Model.Name)
...
...
.Value(Model.Value)
.Events(e => e.Change("onChange").Select("onSelect")) // <=== these are the methods I need to call.
I am going to need to do this on a number of items in the site, so any and all help would be gratefully received.