version 1.3rc bug found with using ko.utils.arrayIndexOf helper

73 views
Skip to first unread message

Joel Hulen

unread,
Nov 30, 2011, 3:50:29 PM11/30/11
to knock...@googlegroups.com
I ran across an issue with version 1.3rc that I did not have in version 1.3beta regarding the ko.utils.arrayIndexOf helper.

Here's a sample of my markup:

<div data-bind="foreach: locations">
    <div id="locationItemView">
        <span class="display-label">Location<span data-bind='text: " " + (ko.utils.arrayIndexOf(locaitonsViewModel.locations, $data)+1)'></span>
    </div>
    ....
    ....
</div>

What is supposed to be displayed is:

Location 1
...
Location 2
...

However, once I moved to 1.3rc from 1.3beta, what I get instead is:

Location 0
...
Location 0
...

I can switch back to 1.3beta and the numbers show up as expected.

The locations object I have bound to my container is simply a ko.observableArray.

Was there a breaking change I missed going from beta to rc1?

Koviko

unread,
Nov 30, 2011, 4:11:05 PM11/30/11
to knock...@googlegroups.com
Are you positive that the typo in "locaitonsViewModel" isn't only in your RC test? I can't think of a reason that the utility function would have changed.

Joel Hulen

unread,
Nov 30, 2011, 4:18:41 PM11/30/11
to KnockoutJS
That typo was a result of me typing in the code rather than copying/
pasting it =)

As previously stated, I can swap between 1.3beta and 1.3rc and it will
work on beta but not on RC.

rpn

unread,
Nov 30, 2011, 4:28:33 PM11/30/11
to knock...@googlegroups.com
Hi Joel-
Can you reproduce your issue off of this fiddle?  http://jsfiddle.net/rniemeyer/ncnJJ/

It is using the latest version from github (RC).

Joel Hulen

unread,
Dec 6, 2011, 8:51:49 AM12/6/11
to KnockoutJS
RPN,

Sorry, I've been on leave until today so didn't get a chance to get in
there and "fiddle" with it.

I've made a slight change to what you had in order to reference jQuery
version 1.7.1 and to add a visibility clause for the output number. On
my project, it loops through properly, just showing a 0 for each item,
but when I updated fiddler, it only shows one location.

Joel

rpn

unread,
Dec 6, 2011, 9:19:01 AM12/6/11
to knock...@googlegroups.com
Can you hit fork or save on the fiddle with changes that are not working or paste them in here?  Thanks!

Joel Hulen

unread,
Dec 6, 2011, 9:31:44 AM12/6/11
to KnockoutJS
I just forked it into a new fiddle since, I guess, it wasn't saving:
http://jsfiddle.net/FLU72/

rpn

unread,
Dec 6, 2011, 9:41:04 AM12/6/11
to knock...@googlegroups.com
I updated it again: http://jsfiddle.net/rniemeyer/FLU72/1/.  Looks like it was just because locations was not an observableArray and the visible binding was accessing it as an observable- locations().  

I'll bet in your app, the problem is here: (ko.utils.arrayIndexOf(locationsViewModel.locations, $data)+1)

Change it to:  (ko.utils.arrayIndexOf(locationsViewModel.locations(), $data)+1)

Joel Hulen

unread,
Dec 6, 2011, 9:52:30 AM12/6/11
to KnockoutJS
Thanks! You're right, it was because I didn't have the two parentheses
after locations. The curious thing is, it worked without the parens in
the ko 1.3 beta version, but not the rc version. Also, I like your
"root" version better rather than having to explicitly call the
ko.utils.arrayIndexOf method ($root.locations.indexOf($data)+1)
Reply all
Reply to author
Forward
0 new messages