[英]How do I get to the beginning or end of the array properly? How do I pass in a reference of currently selected item?
[英]How do I attach an item at the beginning and at the end of an Array?
我正在創建這樣的文本文件:
Coffescript:
file = for post in posts
"#{post.title}\n\n#{post.content}\n\n"
Javascrit:
file = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = posts.length; _i < _len; _i++) {
post = posts[_i];
_results.push("" + post.title + "\n\n" + post.content + "\n\n");
}
return _results;
})();
輸出如下所示:
["Chapter 1↵↵<p>As I made my way uphill, I understoo… of the woods, and continued my way uphill.</p>↵↵", "Chapter 2↵↵<p>I hadn't seen An-Mei for nearly six …pths of my heart, waiting to be awoken.</p><br>↵↵", "Chapter 3↵↵<p>"Sure they allow visitors?" I asked …ht?”</p><p>She gave her head another shake.</p>↵↵", "Chapter 4↵↵<p>Back in the hotel, I thought about w…leading the way—we ventured into the woods.</p>↵↵", "Notes↵↵<p>- Search places where only one word can be used </p>↵↵", "Experiment↵↵<p>There was no one in the streets. I … realized it was a fireplace. </p><p>"</p>↵↵", "Untitled↵↵↵↵"]
現在,我想將文本文件轉換為HTML文檔,以便修改file
以輸出如下內容:
["<html>...", "Chapter 1↵↵<p>As I made my way uphill...]
也許做這樣的事情:
file.attachHeader
file.attachFooter
什么是最簡單的方法(在CoffeScript,JS或Underscore.js中)?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.