meteor-sortablejs
meteor-sortablejs copied to clipboard
TypeError: templateInstance.collection.findOne is not a function
Same problem as: https://github.com/RubaXa/Sortable/issues/768
My manifestation of the problem:
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();
I'm also getting this error... Would love a fix
@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.