特定位置我有一個數據文件,如下所示,如何更新數據到一個文件中的js
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">');
});
但是,如何找到索引後追加?
嘗試使用一些解析器,如https://github.com/tmpvar/jsdom,爲什麼你標記了angularjs :) – codtex
嗨codtex,因爲這與js有關,一些專家喜歡可能來形成角js ... :) –