V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
DaniloSam
V2EX  ›  jQuery

jquery tmpl 传入JSON时,有困惑

  •  
  •   DaniloSam · Oct 5, 2012 · 4027 views
    This topic created in 4955 days ago, the information mentioned may be changed or developed.
    例如有这样一个JSON
    {
    name : "v2ex",
    age : "18",
    location : {
    city : "北京",
    country : "中国"
    }
    }

    在tmpl中如何获得location.city,因为loation不是数组,不能用each
    8 replies    1970-01-01 08:00:00 +08:00
    keakon
        1
    keakon  
       Oct 5, 2012
    你是要遍历map么

    for (key in location) {
    console.log(key + ': ' + a.location[key])}
    }
    lisztli
        2
    lisztli  
       Oct 5, 2012
    var response_json = $.parseJSON(respTxt);
    DaniloSam
        3
    DaniloSam  
    OP
       Oct 5, 2012
    @lisztli
    @keakon
    是我没表述清楚。。。

    已经fix了
    DaniloSam
        4
    DaniloSam  
    OP
       Oct 5, 2012
    @lisztli 近来安好?
    lisztli
        5
    lisztli  
       Oct 5, 2012
    @DaniloSam 加班多,其他都好。 没休假,怎么还在忙呢?
    bitsmix
        6
    bitsmix  
       Oct 6, 2012
    template engine 还是用 {{mustache}} 吧。
    另外,如果问题是 parseJSON 解决的就说明服务器传回来的 content-type 不对。
    我的意思是你的问题其实还是没真正解决。
    DaniloSam
        7
    DaniloSam  
    OP
       Oct 8, 2012
    @lisztli 我加班也多,十一加了五天。。。。还好是在家
    DaniloSam
        8
    DaniloSam  
    OP
       Oct 8, 2012
    @bitsmix 是我用的方式有问题,已经fix了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2374 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 01:15 · PVG 09:15 · LAX 18:15 · JFK 21:15
    ♥ Do have faith in what you're doing.