简体   繁体   English

来自JSON的Javascript模板值

[英]Javascript templating values coming from JSON

I am trying to create a Javascript template with tables and I want to replace the values with JSON data. 我正在尝试使用表创建一个Javascript模板,我想用JSON数据替换值。 But I am having a hard time replacing the template data with JSON. 但我很难用JSON替换模板数据。 maybe I am confusing you but http://jsfiddle.net/k6pJz/ is where I am. 也许我很困惑你,但http://jsfiddle.net/k6pJz/就在我身边。 All your help is highly appreciated. 非常感谢您的所有帮助。

Fixed: http://jsfiddle.net/k6pJz/10/ 修正: http//jsfiddle.net/k6pJz/10/

This code had multiple syntax errors, and malformed JSON. 此代码有多个语法错误和格式错误的JSON。 And would still not have worked afte that. 并且仍然没有在那里工作。 To name a few: 仅举几例:

  • JSON had a smart quote ” instead of the only valid JSON quote character ". JSON有一个聪明的引用“而不是唯一有效的JSON引号字符”。
  • JSON was missing the last closing quote JSON错过了最后一个收盘报价
  • You had had a receiver less method call after a line with a semi colon which doesn't work at all. 在使用半冒号的行之后,你接受了一个较少接收器的方法调用。 foo.innerHTML; .replace('a', 'b')
  • Your second regex does not start with a / character. 你的第二个正则表达式不以/字符开头。
  • You never reassigned the value of the parsed template back to the .data element. 您从未将已解析模板的值重新分配回.data元素。

Lastly, you may want to look into some templating libraries like the one built into jQuery or Mustache . 最后,您可能想要查看一些模板库,例如jQueryMustache中 内置的库。 Thats only two but there are tons, and they make your life much easier. 这只有两个,但有吨,它们让你的生活更轻松。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM