我目前正在研究基于 gridster 的 CMS 模块,它需要让最终用户创建不同的布局,以多次实例化 gridster。
当我遍历应该设置的网格数量并尝试根据定义它们的迭代定义应该使用不同参数调用的回调时,我的问题出现了:当我测试它们时,它们似乎继承了(最后) 相同的值。
我认为这是一个关闭问题,我正在努力解决这个问题,即使阅读了这个论坛的几篇帖子,但没有成功,如果有人能给我一个提示,让我走上正确的道路,我将不胜感激。
这是我的代码:
var gridster= [];
var id_layouts = [];
$(".selectedLayout").each(function(){
id_layouts.push($(this).val());
});
for(i=0; i<id_layouts.length; i++){
makeGridster(i, id_layouts[i]);
}
function makeGridster(index, id_layout){
gridster[index] = $('#blockcompositeGrid'+id_layout+' > ul').gridster({
widget_margins: [10, 10],
widget_base_dimensions: [100, 100],
draggable:{
stop: function(){
return function(i, l){
updateSerialization(i, l)
}(index, id_layout)
}
}
}).data('gridster');
}
function updateSerialization(index, id_layout){
console.log(index, id_layout);
}
网格建立起来,没关系。如您所见,我正在尝试调用一个函数作为拖动动作停止的回调,并且应该使用不同的参数调用该函数。我发现这似乎与我需要的相似,但不幸的是我对咖啡脚本一无所知,并且从'do'的咖啡脚本文档(coffescript.org)我看不出我做错了什么。预先感谢您的任何帮助