typescript - loading observableArray -
i'm using knockout in typescript, want load data returned db observablearray.
i tried below code, got exception:
object doesn't support property or method 'map'
in constructor:
this.boxes = ko.observablearray<box>(data[0].box || []).map(e => new box( e.index, e.title, e.value, e.category )); this.boxes = ko.observablearray<box>([]);
map
method on normal javascript array, not observablearray
, need perform mapping on array response data before passing ko.observablearray<box>()
:
this.boxes = ko.observablearray<box>((data[0].box || []).map(e => new box( e.index, e.title, e.value, e.category )));
Comments
Post a Comment