【问题标题】:how jquery handles map?jquery如何处理地图?
【发布时间】:2014-03-10 11:37:39
【问题描述】:

我正在用 maven 做一个 spring mvc 项目..我想显示一个带有项目的 jqxGrid..我通过 MAP 获取项目..问题是,我有网格但没有显示项目..数据从控制器返回map..jquery 如何处理这个返回的地图??

我的 jquery 代码

       $(document).ready(function () {
             var source =
                {     
                    datatype: "json",
                    type:"GET",
                    url: "account/list",
                    datafields: [
                        { name: 'id' },
                        { name: 'periodname' },
                        { name: 'startdate' },
                        { name: 'enddate' },
                        { name: 'isactive' }
                    ],
                    sort: function () {
                        $("#jqxgrid").jqxGrid('updatebounddata', 'sort');
                        },

                    id: 'id'
                };


             var dataAdapter = new $.jqx.dataAdapter(source, {loadError: function (xhr, status, error) {

                        }
             });

$("#jqxgrid").jqxGrid(
        {

            width: 800,
            source: dataAdapter,
            pageable: true,

            autoheight: true,

            columns: [
              { text: 'Period Name', datafield: 'periodname', width: 200 },
              { text: 'Start Date', datafield: 'startdate', width: 200 },
              { text: 'End Date', datafield: 'enddate', width: 200 },
              { text: 'Active', datafield: 'isactive', width: 200 }
            ]
        });

        $("#addrowbutton").jqxButton({ theme: theme });
        $("#deleterowbutton").jqxButton({ theme: theme });
        $("#updaterowbutton").jqxButton({ theme: theme });

        // initialize jqxGrid
               // });
    });
    </script>

控制器

 @Controller
 @RequestMapping(value="/account")
 public class AccountsController {
@Autowired
private AccountService accountService;
@Autowired
private AccountDAO accountDao;

 @RequestMapping(value="/list",method = RequestMethod.GET,produces="application/json")
 @ResponseBody
 public Map<String, Object> getAccounts(Map<String, Object> map) {

    map.put("all_item_issue_headers", accountDao.getAccounts());
    System.out.println(map);
    return map;

}
}

等待您的回复..谢谢

【问题讨论】:

  • 你的控制器有适当的注释吗?
  • 现在我包括我的控制器..
  • 另一件事它的输出是什么return map; 它是一个对象{} 或对象数组[{}, {}, ...n]
  • 就像这样 {all_item_issue_headers=[com.gerrytan.pizzashop.Accounts@1d7efa3, com.gerrytan.pizzashop.Accounts@1b5d60d, com.gerrytan.pizzashop.Accounts@f805e6, com.gerrytan. Pizzashop.Accounts@14b5721, com.gerrytan.pizzashop.Accounts@145468d, com.gerrytan.pizzashop.Accounts@11af268, com.gerrytan.pizzashop.Accounts@209197]}
  • 我假设你想返回 JSON。你的类路径中有杰克逊库吗?

标签: javascript jquery spring maven


【解决方案1】:

响应将是一个 json。关键是all_item_issue_headers

  var response = yourJson; // this is the map

  var array = yourJson[all_item_issue_headers]; // this is an array

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-30
    • 2016-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    • 2012-05-07
    • 1970-01-01
    相关资源
    最近更新 更多