簡體   English   中英

用Node.js的FileSystem(fs)模塊將多個DOM元素保存和加載為JSON的最干凈方法是什么?

[英]What is the cleanest way to save and load multiple DOM elements as JSON with the FileSystem(fs) Module from Node.js?

我需要將動態添加的DOM元素(可拖動的DIV)保存到文件中,並在以后加載它們。 什么是最干凈的方法來做到這一點?

您可以保存mySql或Mongodb

var mysql      = require('mysql');
var connection = mysql.createConnection({
    host     : 'locahost',
    user     : 'foo',
    password : 'bar',
    database : 'test'
});

// the callback inside connect is called when the connection is good
connection.connect(function(err){
    var sql = "select 'Joe' as name from dual";

    connection.query(sql, function(err, rows, fields) {
        if (err) return console.log(err);
        //  you need to end your connection inside here.
        connection.end();
        console.log(rows[0].name);
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM