knockout.js - Error when using KnockoutObservableArray in TypeScript -
i have following code:
class indexviewmodel { projects: knockoutobservablearray<project>; constructor() { this.projects = ko.observablearray<project>([]); } filteredlist: knockoutcomputed<project[]> = ko.computed(() => { var elements = ko.utils.arrayfilter(this.projects(), (item: project) => { //do }); //return }) }
but when load page, javascript error, says, typeerror: _this.projects not function index-viewmodel_test.js
the rendered javascript part is,
this.filteredlist = ko.computed(function () { var elements = ko.utils.arrayfilter(_this.projects(), function (item) { //return }); //return })
what missing here?
the problem projects
member not yet defined when filteredlist
computed. moving computation in constructor of class solved issue. code:
constructor() { this.projects = ko.observablearray<project>([]); this.filteredlist = ko.computed(() => { var elements = ko.utils.arrayfilter(this.projects(), (item: project) => { //return }); //return }); }
Comments
Post a Comment