ko.observableArray does not trigger subscribe event if I push any items to array

333 views
Skip to first unread message

Tirumal Sutrave

unread,
Jun 15, 2020, 8:36:55 AM6/15/20
to KnockoutJS
I have observable array and have subscribed a callback in it. Callback is not triggered if I push items to observable array. Did not quite get why? am I missing anything here.

Gunnar Liljas

unread,
Jun 15, 2020, 8:51:41 AM6/15/20
to knock...@googlegroups.com
Please show a bit of code.

Den mån 15 juni 2020 kl 14:37 skrev Tirumal Sutrave <sutrave...@gmail.com>:
I have observable array and have subscribed a callback in it. Callback is not triggered if I push items to observable array. Did not quite get why? am I missing anything here.

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/knockoutjs/4ca040b1-bda0-4dc0-94c2-86b0c84580e3o%40googlegroups.com.

Tirumal Sutrave

unread,
Jun 15, 2020, 1:42:52 PM6/15/20
to KnockoutJS
this.data = ko.observableArray([]);
this.data.subscribe(function(newValue){
console.log('This does not execute.');
});

self.data().push('Any random text');


On Monday, 15 June 2020 18:21:41 UTC+5:30, Gunnar Liljas wrote:
Please show a bit of code.

Den mån 15 juni 2020 kl 14:37 skrev Tirumal Sutrave <sutrave...@gmail.com>:
I have observable array and have subscribed a callback in it. Callback is not triggered if I push items to observable array. Did not quite get why? am I missing anything here.

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knock...@googlegroups.com.

Murat Duisenbayev

unread,
Jun 15, 2020, 2:27:03 PM6/15/20
to knock...@googlegroups.com
self.data().push('Any random text');

You are calling push method of js array, wrapped by observableArray. In order for everything to work as intended you should call push of observableArray:

self.data.push('Any random text');

Tirumal Sutrave

unread,
Jun 18, 2020, 1:20:57 AM6/18/20
to KnockoutJS
Thank you.
Reply all
Reply to author
Forward
0 new messages