我是JavaScript的新手,所以请耐心等待。我正在做一个待办事项列表应用程序,该应用程序要求用户在文本框中输入文本,并且在单击按钮或输入密钥时将添加该项目。我可以使用Button Click执行此操作,当我添加Enter键的功能时,按钮停止工作。你能告诉我我做错了什么吗?下面是我的java脚本代码。谢谢。
//server.js
'use strict';
var koa = require('koa');
var app = koa();
var serve = require('koa-static');
var path = require('path');
var router = require('koa-router');
var cfg = require('./config');
var mw = require('./middleware');
app.use(serve(path.resolve(__dirname, '../client')));
app.use(mw.requestTime('Response-time'));
app.use(router(app));
app.use(cfg.db.connect);
require('./routes')(app);
app.get('/api', function *(){
this.body = 'Welcome to API v1';
});
app.use(cfg.db.close);
app.listen(cfg.env.port);
//routes.js
module.exports = function (app){
app.use(require('./api/things').routes());
};
// api/things/index.js
var Router = require('koa-router');
var router = new Router({
prefix: '/api/things'
});
var ctrl = require('./controllers');
router.get('/', ctrl.list);
router.get('/:id', ctrl.get);
router.post('/', ctrl.post);
router.put('/:id', ctrl.put);
router.del('/:id', ctrl.del);
module.exports = router;
// api/things/controllers.js
var r = require('rethinkdb');
var http = require('http');
var parse = require('co-body');
var ctrl = module.exports = {};
ctrl.list = function *(next){
};
ctrl.get = function *(next){
};
ctrl.post = function *(next){
};
ctrl.put = function *(next){
};
ctrl.del = function *(next){
};