2 onlyone1234567890 onlyone1234567890 于 2016.09.06 11:02 提问

我如下遍历之后添加一级菜单没事,但是添加二级的时候菜单的值就是未定义,可以成功添加到数据库,求大神指教

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
href="css/shopbs/catalogDesign.css">

添加菜单
保存
  • 一级菜单
  • 名称&nbsp:&nbsp${navigations.name }
  • 序号&nbsp:&nbsp${navigations.sort }
  • 类型&nbsp:&nbsp${navigations.type }
  • 操作 修改
  • 二级菜单
  • 名称&nbsp:&nbsp${list.name }
  • 序号&nbsp:&nbsp${list.sort }
  • 类型&nbsp:&nbsp${list.type }
  • 操作 修改
  • 二级菜单
  • 名称&nbsp:&nbsp
  • 序号&nbsp:&nbsp
  • 类型&nbsp:&nbsp
  • 操作删除修改
  • 一级菜单
  • 名称&nbsp:&nbsp
  • 序号&nbsp:&nbsp
  • 类型&nbsp:&nbsp
  • 操作删除修改
$("#addDirectoryNavigation").mouseover(function() { $("#addDirectoryLeft .addDirectoryLeft").show(); }).mouseleave(function() { $("#addDirectoryLeft .addDirectoryLeft").hide(); }) $("#addDirectoryNavigation .addDirectoryLeft label").click(function() { $(".aNavigationBar").show(); }); $(" .addNavigation img").click(function() { $("#twoTypesOfBusinesses").show(); }); $(function() { $(".aNavigationBar").on( "click", ".addNavigation", function() { $(this).parents(".aNavigationBar") .find(".addnavigationTwo").show(); }); }); function getId(id, index) { $("#shopmenu_shopId").val(id); } function addShopmenus() { var parinfo = $("#shopmenu_shopId").val(); $("#shopmenu_shopId").val(""); if (parinfo == "" || parinfo == null) { $.ajax({ type : "POST", url : "merchantcenter/addcatalogDesign", data : { name : $("#first_names").val(), sort : $("#first_sorts").val(), type : $("#first_types").val(), }, success : function(result) { if (result.status == 1) { alertMsg.correct("添加一级菜单成功"); $("#navigationDesign").click(); } else { alertMsg.error("非法操作"); } } }); } else { $.ajax({ type : "POST", url : "merchantcenter/addsubshopmenu", data : { name : $("#shopname").val(), sort : $("#" + parinfo + "").val(), parentId : parinfo, type : $("#shoptype").val(), }, success : function(result) { if (result.status == 1) { alertMsg.correct("添加二级菜单成功"); $("#navigationDesign").click(); } else { alertMsg.error("非法操作"); } } }); } } function updatemenus_first() { $.ajax({ type : "POST", url : "merchantcenter/updateShopmenus", data : { id : $("#shopmenu_id").val(), name : $("#shopmenu_name").val(), sort : $("#shopmenu_sort").val(), type : $("#shopmeun_type").val(), }, success : function(result) { if (result.status == 1) { alertMsg.correct("更新一级菜单成功"); $("#navigationDesign").click(); } else { alertMsg.error("更新失败"); } } }); } function updatemenus_second() { $.ajax({ type : "POST", url : "merchantcenter/updateShopmenus", data : { id : $("#list_id").val(), name : $("#list_name").val(), sort : $("#list_sort").val(), type : $("#list_type").val(), }, success : function(result) { if (result.status == 1) { alertMsg.correct("更新二级菜单成功"); $("#navigationDesign").click(); } else { alertMsg.error("更新失败"); } } }); }

这是前台遍历与添加菜单的代码

/**
* 跳转目录设计
*/

@RequestMapping(value = "/tocatalogDesign")
public ModelAndView tocatalogDesign(HttpServletRequest request) {
    Map<String, Object> result = new HashMap<String, Object>();
    Shop shop = (Shop)request.getSession().getAttribute("shop");

    List<Shopmenu>shopmenulist = shopmenuService.queryBySqlQuery("from Shopmenu sm where sm.parentId is null and sm.type=0 and sm.shop.id=?", new Object[]{shop.getId()});
    result.put("shopmenulist", shopmenulist);
    return new ModelAndView("shopbs/order/catalogDesign",result);
}

/**
 *  目录设计 一级菜单
 */
@RequestMapping(value="/addcatalogDesign",method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> addcatalogDesign (HttpServletRequest request,Shopmenu shopmenu){
    System.out.println("进入非法");
    Map<String, Object>result = new HashMap<String,Object>();
    Shop shop = (Shop)request.getSession().getAttribute("shop");
    String warnInfo = "";
    int status = 0;
    if(Common.isNull(shopmenu.getParentId())){
        shopmenu.setShop(shop);
        shopmenu.setType(0);
        shopmenuService.save(shopmenu);
        warnInfo = "添加一级菜单成功";
        status = 1;

    }
    result.put("warnInfo", warnInfo);
    result.put("status", status);
    return result;
}

    /**
 * 目录设计  二级菜单
 */
@RequestMapping(value="/addsubshopmenu",method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> addsubshopmenu(HttpServletRequest request,Shopmenu shopmenu){
    System.out.println("进入合法");
    Map<String, Object>result = new HashMap<String,Object>();
    Shop shop = (Shop)request.getSession().getAttribute("shop");
    String warnInfo = "";
    int status = 0;
    if(!Common.isNull(shopmenu.getParentId())){
        shopmenu.setShop(shop);
        shopmenu.setType(0);
        shopmenuService.save(shopmenu);
        warnInfo = "添加二级菜单成功";
        status = 1;
    }else{

        warnInfo = "非法操作";

    }
    result.put("warnInfo", warnInfo);
    result.put("status", status);
    return result;
}

这是后台查询及添加菜单代码

3个回答

showbo
showbo   Ds   Rxr 2016.09.06 11:09

你问的什么东西。。遍历name和id没有什么直接关系,name一样用document.getElementsByName获取

new_culture
new_culture   2016.09.06 12:50

听你的描述,你自己都是晕的。

u013829202
u013829202   Rxr 2016.09.06 12:59

我也没听懂。这样不好判断啊。 而且前台的id与后台的id有关系吗?与name有关系?

Csdn user default icon
上传中...
上传图片
插入图片