【发布时间】:2015-07-29 20:53:25
【问题描述】:
我正在尝试将数据从文本文件添加到 apigee 数据库。我有几个包含书籍数据的文本文件。
我可以通过此代码添加一本书数据:
function saveData(){
//Initialize our client
var client = new Usergrid.Client({
orgName:"orgname",
appName:"sandbox"
});
//In our options object we set the type of the entitiy
//and we also set any data that goes along with it
//in this case it's the books title.
var options = {
type:"book",
title:"someTitle",
author:"someAuthor",
newElement:"Value"
};
//Let's create our entity, and display the results
//of the creation in the html element with the id of response
client.createEntity(options, function(error, book){
if(error) {
//error saving book
$("#response").append("There was an error!");
alert("Error");
} else {
var uuid = book.get("uuid");
var author = book.get("author");
var title = book.get("title");
$("#response").append("Book saved! Its uuid on our server is: "+uuid+"<br/>");
$("#response").append("The book you saved was: "+title + "<br/>");
$("#response").append("It's author is: "+author);
alert("Its working");
}
});
}
saveData()
如何访问 .txt 文件并从 javascript 获取其他书籍的数据? 我知道 javascript 只允许使用 FileReader() 通过用户输入添加文件。有没有其他方法可以做到这一点?
【问题讨论】:
-
对不起,你的问题不清楚。您是否尝试从 Node.js 读取 TXT 文件?如果是这样,您的问题不是 Apigee 特有的。
标签: javascript node.js apigee