【问题标题】:Adding data text file to apigee database将数据文本文件添加到 apigee 数据库
【发布时间】: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


【解决方案1】:

您提供的代码不会生成任何 .txt 文件,但要回读保存的图书实体,您可以执行以下操作:

      books.fetch(
                function(err, data) { // Success
                    if (err) {
                        alert("read failed");
                    } else {
                        while(books.hasNextEntity()) {
                            var book = books.getNextEntity();
                            alert(book.get("title")); // Output the title of the book
                        }
                    }
                });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多