我刚开始学习MEAN堆栈,需要动态生成动态表单.
要求是导入文档(excel/csv/xml/xls等...)并使用它生成动态表单,以便用户可以更新其数据并再次将其导出到相应的文件中.
因此,为了实现这一点,我将文档转换为JSON格式并将JSON数据存储到MongoDB数据库中.
例如:考虑以下xlsx数据:
ID Name dob Gender
1 user1 7-Dec-87 m
2 user2 8-Dec-87 f
3 user3 9-Dec-87 f
3 user4 4-Dec-87 m
Run Code Online (Sandbox Code Playgroud)
我正在使用xlsx-to-json模块将其转换为JSON格式并将其存储到Mongodb中.
app.post('/myapp', function (req, res) {
//console.log("===========" + req.file.path);
converter({
input: req.file.path,
output: "output.json"
}, function (err, result) {
if (err) {
console.error(err);
} else {
console.log(result);
db.collection('test').insert(result, function (err, doc) {
console.log(err);
res.json(doc);
});
}
});
});
Run Code Online (Sandbox Code Playgroud)
在这里,我从中获取以上数据 Mongodb & express.js
app.get('/myapp', function (req, res) {
db.collection('test').find(function (err, docs) {
console.log(docs); …Run Code Online (Sandbox Code Playgroud) 学习TDD和我的"Hello World"服务器响应的第一个简单测试在Mocha中失败了.我正在使用Mocha.js,Superagent和Expect.js.
当我curl -i localhost:8080,我得到正确的响应和状态代码.
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Mon, 27 Apr 2015 17:55:36 GMT
Connection: keep-alive
Transfer-Encoding: chunked
Hello World
Run Code Online (Sandbox Code Playgroud)
测试代码:
var request = require('superagent');
var expect = require('expect.js');
// Test structure
describe('Suite one', function(){
it("should get a response that contains World",function(done){
request.get('localhost:8080').end(function(res){
// TODO check that response is okay
expect(res).to.exist;
expect(res.status).to.equal(200);
expect(res.body).to.contain('World');
done();
});
});
});
Run Code Online (Sandbox Code Playgroud)
服务器代码:
var server = require('http').createServer(function(req, res){
res.writeHead(200, {"Content-Type":"text/plain"});
res.end('Hello World\n');
});
server.listen(8080, function(){
console.log("Server listening at port 8080"); …Run Code Online (Sandbox Code Playgroud) 我试图让我的前端堆栈在功能上尽可能纯粹和不可变,并且它为这个项目创造了奇迹。
据说所有可以可变实现的算法都可以不可变地实现,那么在javascript中我将如何实现一个不可变的函数记忆器?因为为了通过函数中的不同路径返回,函数内部或外部的某些状态必须改变。
使用以下函数,如何在 javascript 中拥有不可变的记忆?
function once(fn){
let returnValue;
let canRun = true;
return function runOnce(){
if(canRun) {
returnValue = fn.apply(this, arguments);
canRun = false;
}
return returnValue;
}
}
var processonce = once(process);
processonce(); //process
processonce(); //
Run Code Online (Sandbox Code Playgroud) javascript ×3
node.js ×2
expect.js ×1
express ×1
immutability ×1
json ×1
mocha.js ×1
mongodb ×1
superagent ×1