SortableJS / meteor-sortablejs

Reactive reorderable lists.
http://rubaxa-sortable.meteor.com
19 stars 10 forks source link

TypeError: templateInstance.collection.findOne is not a function #8

Open jdmswong opened 8 years ago

jdmswong commented 8 years ago

Same problem as: https://github.com/RubaXa/Sortable/issues/768

My manifestation of the problem:

screen shot 2016-04-04 at 11 17 41 am

caused by dragging and reordering an image

My code: in template

                    {{#sortable items=images}}
                        <img class="gallery-img thumbnail" src="{{this.fname}}">
                    {{/sortable}}

in helper

        return GalleryPhotos.find(
            {
                'gallery_id': myId
            },
            {
                sort: ['order']
            }
        ).fetch();
dylanmcgowan commented 8 years ago

I'm also getting this error... Would love a fix

mikepaszkiewicz commented 8 years ago

@jdmswong @dylanmcgowan Try removing the .fetch() - solved the problem for me.

When using fetch, it assigns templateInstance.collection to a typical collection fetch [ {}, {}, ...] In reality, the package is looking for a cursor to do a findOne on the changed document's collection.

// line 1405 rubaxa_sortable.js
var startOrder = templateInstance.collection.findOne(itemId)[orderField];      
// 

Could have sworn that fetch() has worked in the past, who knows though. The package got moved and isn't actively maintained, so not sure if any behavior was changed before the move.