我是node.js的新手。我必须将数据从节点发送到静态javascript文件。我已经提出了一些我想发送到这个javascript文件的问题:
var model = {
questionSummary:[],
noOfQuestions:0,
init: function () {
// if (!localStorage.getItem("questions")) {
// localStorage.setItem("questions", JSON.stringify([]));
// }
if(!localStorage.getItem("noOfQuestions")){
localStorage.setItem("noOfQuestions",JSON.stringify(0));
}
else{
model.noOfQuestions = localStorage.getItem("noOfQuestions");
}
if (!localStorage.getItem("author")) { //todo
localStorage.setItem("author","Anonymus");
}
if (!localStorage.getItem("currentQuestionId")) {
localStorage.setItem("currentQuestionId", '1');
}
for(var index=1;index<=this.noOfQuestions;index++)
this.questionSummary.push(JSON.parse(localStorage.getItem("question"+index)));
},
getAllQuestions: function () { //todo
return this.questionSummary;
},
increment: function(questionBlockId) {
this.questionSummary[questionBlockId].views++;
},
setter: function(property,value){
localStorage.setItem(property, JSON.stringify(value));
}
};
我希望在我的代码中使用该数据,而不是localStorage。我使用mongoose作为数据库存储并表示为节点框架。
我还没有为此目的制定任何路线,因此从头开始的任何解决方案(建议)都将受到赞赏。