meteor-sortablejs icon indicating copy to clipboard operation
meteor-sortablejs copied to clipboard

TypeError: templateInstance.collection.findOne is not a function

Open jdmswong opened this issue 8 years ago • 2 comments

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();

jdmswong avatar Apr 04 '16 18:04 jdmswong

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

dylanmcgowan avatar Apr 06 '16 19:04 dylanmcgowan

@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.

mikepaszkiewicz avatar Apr 06 '16 22:04 mikepaszkiewicz