【问题标题】:render json using jquery template使用 jquery 模板渲染 json
【发布时间】:2023-03-19 07:14:01
【问题描述】:

我有以下 Json 输出

{ "IDsInThisList":"28184,28181,28180,28178","RowsReturned":"4","List" :[{"ContentID":28184,"ArticleType":"News","Headline":"Mobile Bytes","Article":"<p>HTC CFO Chialin Chang expects the manufacturer&rsquo;s fortunes to change for the better going in to 2014.</p>"}]}

我需要取出“标题”并使用 jquery 模板显示它,我通常使用 {{:Headline}} 但由于某种原因它不起作用,可能是因为它在“列表”中,我如何渲染“标题” ?

【问题讨论】:

  • json 不直接填充您必须使用任何 javascript 模板引擎的 html:例如:JADE

标签: javascript jquery json templates


【解决方案1】:

使用JSON.parse()解析字符串,然后使用a.List[0].Headline访问

var a=JSON.parse('{ "IDsInThisList":"28184,28181,28180,28178","RowsReturned":"4","List" :[{"ContentID":28184,"ArticleType":"News","Headline":"Mobile Bytes","Article":"<p>HTC CFO Chialin Chang expects the manufacturer&rsquo;s fortunes to change for the better going in to 2014.</p>"}]}');

console.log(a.List[0].Headline);

Fiddle Demo

【讨论】:

  • 但是如何使用Jquery模板显示呢?
  • 你说的Jquery模板是什么意思?
猜你喜欢
  • 2011-12-27
  • 2010-12-18
  • 1970-01-01
  • 1970-01-01
  • 2016-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多