0

我正在尝试绑定从 servlet 检索到的 JSON 数据对象。

$("#mainVerticalMenu").kendoMenu({
            dataSource : new kendo.data.DataSource({
                  transport: {
                      read: {
                          url: "net/samso/action/MenuAction?func_flag=getMenu&user_id=nexol", // the servlet url
                          dataType: "json",
                      }
                  },
                  schema: { // describe the result format
                      model : {
                          fields : {
                            text : {
                                type : "string"
                            },
                            value : {
                                type : "string"
                            },
                            subItemList: [{                                    // Sub item collection
                                text : {
                                    type : "string"
                                },
                                value : {
                                    type : "string"
                                }
                            }]
                          }
                      }
                  }
            })
        });

从 servlet 中给出的 JSON 格式如下:

等级制度:

Text
Value
subItemList (ItemObject nested inside the menuitem)
   - Text
   - Value

示例 JSON:

最终看起来像:

[{"text":"OuterMenu1","value":"menu1","subItemList":[{"text":"subMenuItem1","value":"subMenu1"},{"text":"subMenuItem2","value":"subMenu2"}]}]

直接调用 servlet 时收到的实际 JSON:

[{"text":"Communication","value":"BASE_01","subItemList":[{"text":"상품소개조회","value":"BASE_01"},{"text":"공지사항","value":"BASE_02"},{"text":"의견수렴","value":"BASE_04"},{"text":"사용자관리","value":"BASE_05"},{"text":"받은쪽지","value":"BASE_07"},{"text":"보낸쪽지","value":"BASE_08"},{"text":"자유게시판","value":"BASE_09"},{"text":"매장/마진율 정보","value":"BASE_10"}]},{"text":"매입관리","value":"BUY_01","subItemList":[{"text":"입고/입고반품현황","value":"BUY_01"},{"text":"수평이동요청","value":"BUY_02"},{"text":"수평이동승인/조회","value":"BUY_03"}]},{"text":"판매관리","value":"SALE_01","subItemList":[{"text":"판매및반품등록","value":"SALE_01"},{"text":"판매및반품조회","value":"SALE_02"},{"text":"판매일보","value":"SALE_04"},{"text":"기간별판매현황","value":"SALE_05"},{"text":"판매순위분석","value":"SALE_06"},{"text":"판매순위표","value":"SALE_07"},{"text":"타사등록","value":"SALE_08"},{"text":"타사판매등록","value":"SALE_09"},{"text":"타사판매조회","value":"SALE_10"}]},{"text":"수불관리","value":"SUBUL_01","subItemList":[{"text":"상품주문등록","value":"SUBUL_01"},{"text":"상품주문조회","value":"SUBUL_02"},{"text":"미입고명세서","value":"SUBUL_10"},{"text":"일별수불현황","value":"SUBUL_04"},{"text":"재고현황","value":"SUBUL_05"},{"text":"수불 일/월보","value":"SUBUL_09"},{"text":"품목별수불현황","value":"SUBUL_08"},{"text":"재고조정","value":"SUBUL_11"},{"text":"타매장재고현황","value":"SUBUL_07"}]},{"text":"영업관리","value":"BUSS_01","subItemList":[{"text":"영업판매배치등록","value":"BUSS_01"},{"text":"영업판매조회","value":"BUSS_02"},{"text":"영업주문배치등록","value":"BUSS_03"},{"text":"영업주문조회","value":"BUSS_04"},{"text":"매장별 재고/수불현황","value":"BUSS_05"}]},{"text":"AS관리","value":"AS_01","subItemList":[{"text":"A/S의뢰 관리","value":"AS_01"}]},{"text":"관리자","value":"SUP_06","subItemList":[{"text":"기초코드관리","value":"SUP_06"},{"text":"시스템관리","value":"SUP_05"},{"text":"그룹관리","value":"SUP_02"},{"text":"그룹소속관리","value":"SUP_03"},{"text":"그룹권한관리","value":"SUP_04"},{"text":"매장등록현황","value":"SUP_01"},{"text":"마진율조회","value":"SUP_07"},{"text":"상품코드별권한등록","value":"SUP_08"},{"text":"거래처별상품권한등록","value":"SUP_09"},{"text":"마감현황","value":"SUP_10"},{"text":"SAP송수신기록조회","value":"SUP_12"}]},{"text":"회계","value":"ACCT_01","subItemList":[{"text":"WEB-POS 사용자현황","value":"ACCT_01"},{"text":"WEB-POS 입금등록","value":"ACCT_02"}]}]

我想问两个问题:

  1. servlet 根本没有被调用,即使我已经在数据源中明确声明了传输 URL。

  2. 上述模式对于声明外部菜单项和在其中嵌套项是否正确?

4

1 回答 1

2

没有调用 servlet,因为 Kendo Menu 没有定义DataSource用于加载其内容的 a。但这并不意味着你不能这样做:是的,你可以!

你应该做的是:

  1. 定义一个空菜单。
  2. 定义一个数据源。
  3. 在 DataSource 中手动触发读取
  4. Append received data to the original menu.

The code:

var menu = $("#menu").kendoMenu({}).data("kendoMenu");
var ds = new kendo.data.DataSource({
    transport: {
        read: {
            url     : "menu.json",
            dataType: "json"
        }
    },
    schema   : {
        data: function (data) {
            menu.append(data);
        }
    }
});
ds.read();

About your second question regarding the format of the JSON: replace subItemList by items, that's it. The entries on your JSON would look like:

[
    {
        "text"       : "Communication",
        "value"      : "BASE_01",
        "items": [
            {
                "text" : "상품소개조회",
                "value": "BASE_01"
            },
            {
                "text" : "공지사항",
                "value": "BASE_02"
            },
            {
                "text" : "의견수렴",
                "value": "BASE_04"
            },
            {
                "text" : "사용자관리",
                "value": "BASE_05"
            },
            {
                "text" : "받은쪽지",
                "value": "BASE_07"
            },
            {
                "text" : "보낸쪽지",
                "value": "BASE_08"
            },
            {
                "text" : "자유게시판",
                "value": "BASE_09"
            },
            {
                "text" : "매장/마진율 정보",
                "value": "BASE_10"
            }
        ]
    },
    {
        "text"       : "매입관리",
        "value"      : "BUY_01",
        "items": [
            {
                "text" : "입고/입고반품현황",
                "value": "BUY_01"
            },
            {
                "text" : "수평이동요청",
                "value": "BUY_02"
            },
            {
                "text" : "수평이동승인/조회",
                "value": "BUY_03"
            }
        ]
    },
    {
        "text"       : "판매관리",
        "value"      : "SALE_01",
        "items": [
            {
                "text" : "판매및반품등록",
                "value": "SALE_01"
            },
            {
                "text" : "판매및반품조회",
                "value": "SALE_02"
            },
            {
                "text" : "판매일보",
                "value": "SALE_04"
            },
            {
                "text" : "기간별판매현황",
                "value": "SALE_05"
            },
            {
                "text" : "판매순위분석",
                "value": "SALE_06"
            },
            {
                "text" : "판매순위표",
                "value": "SALE_07"
            },
            {
                "text" : "타사등록",
                "value": "SALE_08"
            },
            {
                "text" : "타사판매등록",
                "value": "SALE_09"
            },
            {
                "text" : "타사판매조회",
                "value": "SALE_10"
            }
        ]
    },
    {
        "text"       : "수불관리",
        "value"      : "SUBUL_01",
        "items": [
            {
                "text" : "상품주문등록",
                "value": "SUBUL_01"
            },
            {
                "text" : "상품주문조회",
                "value": "SUBUL_02"
            },
            {
                "text" : "미입고명세서",
                "value": "SUBUL_10"
            },
            {
                "text" : "일별수불현황",
                "value": "SUBUL_04"
            },
            {
                "text" : "재고현황",
                "value": "SUBUL_05"
            },
            {
                "text" : "수불 일/월보",
                "value": "SUBUL_09"
            },
            {
                "text" : "품목별수불현황",
                "value": "SUBUL_08"
            },
            {
                "text" : "재고조정",
                "value": "SUBUL_11"
            },
            {
                "text" : "타매장재고현황",
                "value": "SUBUL_07"
            }
        ]
    },
    {
        "text"       : "영업관리",
        "value"      : "BUSS_01",
        "items": [
            {
                "text" : "영업판매배치등록",
                "value": "BUSS_01"
            },
            {
                "text" : "영업판매조회",
                "value": "BUSS_02"
            },
            {
                "text" : "영업주문배치등록",
                "value": "BUSS_03"
            },
            {
                "text" : "영업주문조회",
                "value": "BUSS_04"
            },
            {
                "text" : "매장별 재고/수불현황",
                "value": "BUSS_05"
            }
        ]
    },
    {
        "text"       : "AS관리",
        "value"      : "AS_01",
        "items": [
            {
                "text" : "A/S의뢰 관리",
                "value": "AS_01"
            }
        ]
    },
    {
        "text"       : "관리자",
        "value"      : "SUP_06",
        "items": [
            {
                "text" : "기초코드관리",
                "value": "SUP_06"
            },
            {
                "text" : "시스템관리",
                "value": "SUP_05"
            },
            {
                "text" : "그룹관리",
                "value": "SUP_02"
            },
            {
                "text" : "그룹소속관리",
                "value": "SUP_03"
            },
            {
                "text" : "그룹권한관리",
                "value": "SUP_04"
            },
            {
                "text" : "매장등록현황",
                "value": "SUP_01"
            },
            {
                "text" : "마진율조회",
                "value": "SUP_07"
            },
            {
                "text" : "상품코드별권한등록",
                "value": "SUP_08"
            },
            {
                "text" : "거래처별상품권한등록",
                "value": "SUP_09"
            },
            {
                "text" : "마감현황",
                "value": "SUP_10"
            },
            {
                "text" : "SAP송수신기록조회",
                "value": "SUP_12"
            }
        ]
    },
    {
        "text"       : "회계",
        "value"      : "ACCT_01",
        "items": [
            {
                "text" : "WEB-POS 사용자현황",
                "value": "ACCT_01"
            },
            {
                "text" : "WEB-POS 입금등록",
                "value": "ACCT_02"
            }
        ]
    }
]
于 2013-03-20T07:56:24.727 回答