Groups
Groups
Sign in
Groups
Groups
KnockoutJS
Conversations
About
Send feedback
Help
observableArray.removeAll() on empty array triggers update
49 views
Skip to first unread message
Fabian Sturm
unread,
Apr 13, 2013, 11:45:29 AM
4/13/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to knock...@googlegroups.com
Hi,
I just figured out that
self.selectedConfigurations = ko.observableArray([]);
...
self.selectedConfigurations.removeAll();
triggers an update of all dependant variable even thou the array was already empty.
Is this the intended behaviour?
I now will have to wrap all the removeAll calls with:
if (self.selectedConfigurations().length > 0) {
self.selectedConfigurations.removeAll();
}
Or is there a shorter version for that?
Thanks, Fabian
Michael Best
unread,
Apr 15, 2013, 3:51:05 PM
4/15/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to knock...@googlegroups.com
You can extend observableArray by adding to ko.observableArray.fn:
ko.observableArray.fn.myRemoveAll = function() {
if (this.peek().length > 0) {
this.removeAll();
}
};
-- Michael
Reply all
Reply to author
Forward
0 new messages