Comparing arrays with ko.utils.compareArrays

909 views
Skip to first unread message

Uğur Tılıkoğlu

unread,
Apr 26, 2013, 8:46:05 AM4/26/13
to knock...@googlegroups.com
Hi everybody,

I am trying to compare two arrays with ko.utils.compareArrays , but i cannot get any success. Am i missing something?

This fiddle is comparing two arrays with exactly same rows, i expect a result of "retained" rows, but it produces "deleted" and "added" rows.

http://jsfiddle.net/tilikoglu/tTsKk/3/

Thanks
Ugur

Gunnar Liljas

unread,
Apr 26, 2013, 9:33:44 AM4/26/13
to knock...@googlegroups.com
The thing is, the rows are not exactly the same, they just have the
same data inside, and compareArrays doesn't care about that.

Just as an example, I made a modification to compareArrays, which
takes a comparison delegate.

http://jsfiddle.net/tTsKk/5/

2013/4/26 Uğur Tılıkoğlu <tili...@gmail.com>:
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Uğur Tılıkoğlu

unread,
Apr 26, 2013, 11:21:37 AM4/26/13
to knock...@googlegroups.com
Hi Gunnar,

I will try this method and share my opinions.

Thank you
ugur


Michael Best

unread,
Apr 26, 2013, 4:44:08 PM4/26/13
to knock...@googlegroups.com
This is cool. But you probably also want to use the delegate in the move-tracking part, line 75: if (notInSmlItem['value'] === notInBigItem['value']) {

Gunnar Liljas

unread,
Apr 27, 2013, 5:31:29 AM4/27/13
to knock...@googlegroups.com
Yes. It was more an example to show why the original compareArrays
doesn't work. However, I think having a comparison delegate option
makes sense in many cases.

/G

2013/4/26 Michael Best <mb...@dasya.com>:
Reply all
Reply to author
Forward
0 new messages