我正在开发一个ps模块,让您可以分类产品附件并将它们显示在前面的产品页面中。在模块类中使用ajax处理<select>值,prestashop 1.6
即时通讯使用可拖动列表和附件,当您将它们拖放到类别时,它将变为选项标签,每个类别都有一个选择标签,用于放置附件。
我想保存附件和它们被删除的类别,所以我想做一个ajax调用将数据带到我的模块类,但我是新的与ajax和不能接近它。
这是世界卫生大会我做:
的js代码(正确.tpl内):
<script>
$(".droptrue").droppable({
drop: function(event, ui) {
//add <option> tag when an attachment is dropped to category's select
$(event.target).append('<option value="' + ui.draggable.attr('id') + '" selected>'+ui.draggable.text()+'</option>');
//remove the <li> wich contained the attachment data
ui.draggable.fadeOut("slow").remove();
var val = $('#categoryAttachmentArr').val();
//var tab = val.split(',');
//for (var i=0; i < tab.length; i++)
//if (tab[i] == $(this).val())
// return false;
//create an array with the next format: 'id_category(1)'-'id_attachment(1)','id_category(2)'-'id_attachment(2)'[....]
//the comma will be the main character that will be splitted
$('#categoryAttachmentArr').val(val + ui.doppable.attr('id') + '-' + ui.draggable.attr('id') +',');
}
});
$('#submitAddProduct').click(function(e){
$.ajax({
type: 'POST',
url: baseDir + 'modules/adjuntos/classes/CategoryAttachment.php',
data: {
ajax: true,
action: \'CategoryArray\',
cat_array: $('#categoryAttachmentArray').val(),
}
dataType: 'json',
success: function(json) {
console.log($('#categoryAttachmentArray').val());
}
});
})
$(".ui-state-default").draggable({
revert: "valid",
});
</script>
而我的等级:
class CategoryAttachment extends Objectmodel
{
//other functions
public function ajaxProcessCategoryArray()
{
$CategoryAttachmentArr = Tools::getValue('cat_array')
}
}
谢谢回答!所以我必须创建一个新的控制器,或者只需要创建一个新的PHP文件来处理这个问题。或者也许使用一个实际的管理控制器(例如产品控制器)。 你能举个例子吗? –
您可以在模块中使用自定义(前/管理员)控制器,或使用页面上可用的Hooks来处理您的ajax过程。建议第一种方法。 –