【发布时间】:2017-11-17 18:18:30
【问题描述】:
我有一个文件,数据如下,
Test.txt,
<template class="get" type="amp-mustache">
<div class="divcenter">
/////Need to append data at this point/////
</div>
</template>
我有如下数据
[
{'text':'<p>grapes</p>'},
{'text':'<p>banana</p>'},
{'text':'<p>orange</p>'},
{'text':'<p>apple</p>'},
{'text':'<p>gua</p>'}
]
应该是追加数据后,
<template class="get">
<div class="divcenter">
<p>grapes</p>
<p>banana</p>
<p>orange</p>
<p>apple</p>
<p>gua</p>
</div>
</template>
我的代码,
fs.readFile(Test.txt, function read(err, data) {
if (err) {
throw err;
}
var file_content = data.toString();
var c = file_content.indexOf(' <div class="divcenter">');
});
但是找到索引后如何追加?
【问题讨论】:
-
尝试使用像 github.com/tmpvar/jsdom 这样的解析器,你为什么要标记 angularjs :)
-
嗨 codtex 因为这与 js 相关,一些专家喜欢可能来自 angular js...:)
标签: javascript angularjs node.js mean-stack fs