我想在服务器端构建我的html代码。
为了做到这一点,我使用了模板javascript库。
我试着让这段代码工作,但它就是不修改原始的html模板代码...
var Plates = require("plates")
var html = "<h1>Template test with plates</h1>"
+ "<p my-content>This should be erased...</p>";
var data = { 'my-content': "It is: "+new Date() };
console.log(Plates.bind(html, data));这应该输出日期而不是默认字符串,但它没有...
我也尝试过mapper,但没有成功:
var Plates = require("plates")
var html = "<h1>Template test with transparency</h1>"
+ "<p my-content>This should be erased...</p>";
var data = { 'content': "It is: -> "+new Date() };
var map = Plates.Map();
map.where('my-content').use('content');
console.log(Plates.bind(html, data, map));我得到的唯一有效的代码示例如下:
var Plates = require("plates")
var html = "<h1>Template test with transparency</h1>"
+ "<p my-content='changeable'>This should be erased...</p>";
var data = { 'content': "It is: -> "+new Date() };
var map = Plates.Map();
map.where('my-content').is("changeable").use('content');
console.log(Plates.bind(html, data, map));但是我不需要my-content='changeable'标签,我只需要my-content标签...
有人能帮帮我吗?
我也接受其他nodejs模板库的建议,它们确实像这样工作(如果这解决了我的问题)……
发布于 2015-08-13 00:02:14
您的代码无法工作,因为您正在使用my-content作为属性。
您需要使用id属性,并将其更改为<p id="my-content">才能使bind()工作。
例如:
var Plates = require("plates")
var html = '<h1>Template test with plates</h1>'
+ '<p id="my-content">This should be erased...</p>';
var data = { 'my-content': "It is: "+new Date() };
console.log(Plates.bind(html, data));https://stackoverflow.com/questions/31968416
复制相似问题