我正在构建一个带有后端和前端的Web应用程序,后端是用scala构建的,前端构建在html,css,jquery(backbone.js,jquery.js,underscore.js)中.
我该如何创建登录?所以基本上你可以看到前端作为一个应用程序,我们只向其余的后端发出json请求.
感谢帮助.
main.js
var http = require('http');
var UserModel = require('./models/user.js');
var server = http.createServer(function(req, res){
UserModel.create({
}), function(e, o){
if(e) { console.log(e); } else {
} console.log(o); }
});
}).listen(3000);
Run Code Online (Sandbox Code Playgroud)
connections.js
var mongo = require('mongodb');
module.exports = {
dbMain: new mongo.Db('main', new mongo.Server('127.0.0.1', 27017, { auto_reconnect: true }, {})),
dbLog: new mongo.Db('log', new mongo.Server('127.0.0.1', 27017, { auto_reconnect: true }, {}))
};
Run Code Online (Sandbox Code Playgroud)
/models/user.js
var mongodb = require('mongodb');
var db = require('./connections.js').dbMain;
module.exports = {
create: function(newData, callback){
db.open(function(e, db){
db.collection('users', function(e, collection){ …Run Code Online (Sandbox Code Playgroud) 我正在编写一个API,而且我遇到了根据传入请求混合异步和同步代码的问题,请看下面的示例.
routes.js
module.exports = [
{
method: 'GET',
path: '/',
controller: 'main',
action: 'main',
description: 'lists the API functionality',
access: 'auth'
},
{
method: 'POST',
path: '/users',
controller: 'users',
action: 'create',
description: 'creates a new user',
fields: {
fullName: {
format: {
min: 2,
max: 64,
minWords: 2,
disableDoubleSpaces: true
},
description: 'the full name of the new user',
examples: 'Thomas Richards, Richard Jones, Michael J. Fox, Mike Vercoelen, John Johnson'
},
email: {
format: {
min: 2,
max: 64, …Run Code Online (Sandbox Code Playgroud) 让我们说我有这个观点:
var HomeView = Backbone.View.extend({
el: '#application',
initialize: function() {
this.template = template; // Comes from requireJS (not relevant)
this.$elements = {};
},
render: function() {
this.$el.html(this.template);
this.$elements = {
signIn: {
email: $('#sign-in-email'),
password: $('#sign-in-password')
}
};
// Demonstration.
this.$elements.signIn.email.myPluginInit();
this.$elements.signIn.password.myPluginInit();
//
// NOTE: How to handle the events?
//
}
});
Run Code Online (Sandbox Code Playgroud)
我有这个.$ elements对象,它将包含我DOM中的所有对象,如何将事件放在它们上面因为这个解决方案它们是可变的.这就是我以前做的事情(参见backbone.org).
var HomeView = Backbone.View.extend({
events: {
'click #sign-in-email': 'clickedSignInEmail',
'focus #sign-in-password': 'focusSignInPassword'
}
});
Run Code Online (Sandbox Code Playgroud) 我想在mongoose模式验证规则中构建"minLength"和"maxLength",目前的解决方案是:
var blogSchema = new Schema({
title: { required: true, type: String }
});
blogSchema.path('title').validate(function(value) {
if (value.length < 8 || value.length > 32) return next(new Error('length'));
});
Run Code Online (Sandbox Code Playgroud)
但是我想这应该通过添加自定义架构规则来简化:
var blogSchema = new Schema({
title: {
type: String,
required: true,
minLength: 8,
maxLength: 32
}
});
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做,这甚至可能吗?
基本上我正在创建一个Gulp任务,它复制一个文件夹及其所有子文件夹,但我希望它跳过2个目录,如下所示:
var gulp = require('gulp');
gulp.task('copy', function () {
return gulp.src(['./src/**', '!./src/scripts/', '!./src/styles/'])
.pipe(gulp.dest('./dist'));
});Run Code Online (Sandbox Code Playgroud)
但它不起作用,它将复制src目录,包括src/scripts和src/styles子文件夹.
除了src/scripts和src/styles文件夹之外,我怎么能让它复制src目录+子文件夹(和子子文件夹).
我有以下代码:
!function($){
$.keys = {
backspace: 8,
tab: 9,
enter: 13,
escape: 27,
space: 32,
pageUp: 33,
pageDown: 34,
end: 35,
home: 36,
left: 37,
up: 38,
right: 39,
down: 40,
delete: 46,
numpadEnter: 108,
comma: 188
};
}(window.jQuery);
Run Code Online (Sandbox Code Playgroud)
我想构建一个函数,返回一个键代码的字符串,例如:
$.keys.toString = function(key){
switch(key){
case $.keys.backspace:
return 'backspace';
}
};
Run Code Online (Sandbox Code Playgroud)
该列表将更大,并支持$ .keys对象的所有键.但是有可能$ .keys.toString函数实际上使用$ .keys数组将int转换为字符串,所以我不必创建switch语句.
像getKeyFromObjectValue这样的东西?
感谢帮助 :)
我正在使用Express.js框架在Node.js中构建REST JSON Api.对于身份验证,我使用HTTP basic.到目前为止这是我的代码:
var express = require('express');
var app = express();
app.configure(function(){
app.use(express.bodyParser());
});
// Http basic auth.
app.use(function(req, res, next){
if(req.headers.authorization && req.headers.authorization.search('Basic ') === 0){
var header = new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString();
var headerSplit = header.split(':');
var username = headerSplit[0];
var password = headerSplit[1];
if(username && password && (username.length >= 4 && password.length >= 2){
if(auth(username, password)){
next(); return;
} else {
res.send('Authentication required', 401);
}
}
} else {
res.header('WWW-Authenticate', 'Basic realm="Login with username/password"');
res.send('Authentication required', …Run Code Online (Sandbox Code Playgroud) 我有以下用户模型:
var UserModel = Backbone.Model.extend({
urlRoot: 'user',
defaults: {
fullName: null,
email: null,
password: null
}
});
Run Code Online (Sandbox Code Playgroud)
现在我们可以CRUD(注册,更新信息,删除和获取用户)但是如何:
我如何扩展我的UserModel以实现这一目标?
我在数学和几何方面都不擅长,所以如果有人可以帮我创建以下形状,我会很高兴:

所以基本上形状存在于3个矩形中,我得到前两个完美的变换矩阵,但我不能得到最后一个匹配形状(参见上面的链接img)
HTML
<div class="shape">
<div class="shape-rect-one"></div>
<div class="shape-rect-two"></div>
<div class="shape-rect-three"></div>
</div>?
Run Code Online (Sandbox Code Playgroud)
CSS
.shape {
perspective: 1000px;
}
.shape div {
width: 100px;
height: 100px;
opacity: 0.4;
background-color: #333;
}
.shape-rect-one {
z-index: 100;
transform: matrix(1, -0.40, 0, 1, 0, 0);
-webkit-transform: matrix(1, -0.40, 0, 1, 0, 0);
}
.shape-rect-two {
z-index: 200;
transform: matrix(1, -0.40, 0, 1, 0, 0);
-webkit-transform: matrix(1, 0.40, 0, 1, 0, 0);
}
.shape-rect-three {
z-index: 300;
}?
Run Code Online (Sandbox Code Playgroud)