实现无法在Meteor中使用的可排序图像集合 [英] Implementing a sortable Image collection not working in Meteor
本文介绍了实现无法在Meteor中使用的可排序图像集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无法实现可排序的图片集合
Implementing a sortable Image collection doesn't work
<template name="gallery">
<div id="grid-container" class="cbp-l-grid-agency grid">
{{#each images getCurrentCategory}}
{{> image}}
{{/each}}
</div>
</template>
Template.gallery.created = function(){
Tracker.autorun(function () {
Meteor.subscribe('images'), self.limit.get()
});
}
Template.gallery.rendered = function(){
//// Image reordering /////
this.$('#Images').sortable({
stop: function(e, ui) {
el = ui.item.get(0)
before = ui.item.prev().get(0)
after = ui.item.next().get(0)
if(!before) {
newRank = Blaze.getData(after).rank - 1
} else if(!after) {
newRank = Blaze.getData(before).rank + 1
}
else
newRank = (Blaze.getData(after).rank +
Blaze.getData(before).rank)/2
Images.update({_id: Blaze.getData(el)._id}, {$set: {rank: newRank}})
}
})
}
Template.gallery.helpers({
'getCurrentCategory':
function() {
return Template.instance().currentcategory.get();
},
'category': function(){
var allImages = Images.find().fetch();
var categoryList = _.uniq(allImages, false, function(d) {return d.category});
var a = _.pluck(categoryList, "category");
return a;
},
'images': function (currentcategory) {
if(currentcategory == 'all' || !currentcategory){
return Images.find({},{sort: {rank: -1}});
}
return Images.find({category:currentcategory});
}
});
需要在代码中添加或修改什么?
What else need to be added or to be modified in the code ?
推荐答案
在您的代码中,我们没有:
In your code, we do not have:
- 名为Images的集合
- 名为image的模板
根据我所拥有的,我可以说:
And from what I have, I can say :
- Template.gallery.rendered应该重命名为Template.gallery.onRendered(function(){...});
- 在呈现的函数中,调用
sortable
.如果要使用库来操作DOM,则可能是问题.尝试仅使用blaze进行操作,然后可以进行测试以查看您的库是否可以使用blaze. - Meteor.subscribe('images')只能被调用一次
- Template.gallery.rendered should be renammed into Template.gallery.onRendered(function(){...});
- In your rendered function, you call
sortable
. If you want to manipulate the DOM with a library, it may be the issue. Try to do it using only blaze, and then you can test to see if your library is ok with blaze. - Meteor.subscribe('images') can be call only 1 time
这篇关于实现无法在Meteor中使用的可排序图像集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文