mart1nN

Controller 中通过 ModelAndView.addObject("map" ,map)的形式传入一个 map 类型的参数,请问前台怎么获取

  •  
  •   mart1nN · Aug 22, 2019 · 3811 views
    This topic created in 2633 days ago, the information mentioned may be changed or developed.

    模板引擎是 freemarker

    不需要将数据直接显示在 html 页面上,希望能在 js 中取到并做一定的处理

    4 replies  •  2019-08-22 11:00:16 +08:00
    wa8n
    wa8n
    Aug 22, 2019 via iPhone
    1
    转 json 字符串传前端,或者在 script 里面遍历 map
    MrTangKe
    MrTangKe
    Aug 22, 2019
    2
    JSON.stringify(params)
    mart1nN
    mart1nN
    OP
    Aug 22, 2019
    3
    @wangsongyan 我目前在 controller 中把 map 变成字符串传上去了,前台通过 hidden 类型的 text 用${..}获取到了值,然后再在 js 中处理。我刚刚接触 fm,请教一下你说的 script 遍历 map 是怎么操作
    wa8n
    wa8n
    Aug 22, 2019❤️1
    4
    @mart1nN script 里面定义 map,通过 Freemarker 把数据遍历出来,类似于:var data = { /*遍历 key 和 value*/ };
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   980 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:16 · PVG 03:16 · LAX 11:16 · JFK 14:16
    ♥ Do have faith in what you're doing.