-
链接地址:
js端代码
this.evenDrag = function() {
// 重新排序
var sort = 0;
var menuSortArr = new Object();
var i = 0;
$(".bannerSort").each(function(){
var id = $(this).attr("id");
sort ++;
menuSortArr[i] = {id:id, sort:sort};
i ++ ;
var subSort = 0;
$(this).find(".sonMenu").each(function(){
var id = $(this).attr("id");
subSort ++;
menuSortArr[i] = {id:id, sort:subSort};
i ++ ;
});
$(this).find(".parent-menu-item-num").html("#" + sort);
});
owner.updateMenusSort(menuSortArr);
};
this.updateMenusSort = function (menuSort) {
var YII_CSRF_TOKEN =$('#YII_CSRF_TOKEN').val();
$.post('index.php?r=shop/DragSort',{data:menuSort, YII_CSRF_TOKEN:YII_CSRF_TOKEN},function(ret){
if (200 == ret.code) {
initData = ret.data.menus;
owner.Initialize();
} else {
alert(ret.message)
}
},'json');
};
$(".phone-right").dragsort({
dragSelector: ".mask-left",
dragBetween: true,
dragEnd: owner.evenDrag,//拖动完成后做的事
placeHolderTemplate: "
"
});
php代码
/**
* Banner拖动排序
*/
public function actionDragSort()
{
$data = request()->getPost("data");
if($data){
foreach ($data as $row) {
$bannerInfo = array( 'position' => $row['sort']);
$ret = ShopModule::Instance()->addBanner($bannerInfo, $row['id']);
}
}
}