好吧,我在正则表达式上非常新,特别是在js regexp上
我正在寻找与十六进制颜色语法匹配的正则表达式(如"#34ffa6")然后我关注w3school页面:Javascript RegExp对象
那是我的正则表达式: / ^#[0-9a-f] {6}/i
它似乎工作但是,如果我想要它也匹配"短十六进制颜色语法"形式?(比如"#3fa"),这可能吗?我尝试使用caracter | 但也许我的语法错了......
Thx提前和抱歉肯定是坏英语(我是意大利人......)
这是我的代码:
var userSchema = new mongoose.Schema({
email: String,
password: String,
role: Something
});
Run Code Online (Sandbox Code Playgroud)
我的目标是定义角色属性以具有特定值('admin','member','guest'等等),实现这一目标的更好方法是什么?提前致谢!
我的应用程序有多个语言环境(it,en).
我需要翻译所有路线.例如,我有条件和条件页面必须路径(每个区域一个):
it/terminien/terms我需要做的事情比:
// routes.js
const routes = (
<Route path="/" component={App}>
<IndexRoute component={HomePage} />
<Route path="(it/termini)(en/terms)" component={TermsPage} />
<Route path="*" component={NotFoundPage} />
</Route>
)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,这个时髦的解决方案对于应用程序的可伸缩性来说并不是那么好.
我正在尝试使用mongodb客户端"Robomongo" http://robomongo.org/
它工作正常,但我无法理解如何访问在"函数"部分创建的函数...
我想测试mapReduce功能,所以我创建了map()和reduce()函数,但是当我在shell上编写时:
db.<name_of_collection>.mapReduce(map, reduce, {out: {inline: 1}});
Run Code Online (Sandbox Code Playgroud)
Robomongo给我以下错误:
ReferenceError: map is not defined (shell):1
Run Code Online (Sandbox Code Playgroud)
我也尝试过这样的:
db.<collection_name>.mapReduce(db.system.js.map, db.system.js.reduce, {out: {inline: 1}});
Run Code Online (Sandbox Code Playgroud)
但同样,事情似乎是错误的......
uncaught exception: map reduce failed:{
"errmsg" : "exception: JavaScript execution failed: ReferenceError: learn is not defined",
"code" : 16722,
"ok" : 0
}
Run Code Online (Sandbox Code Playgroud) 我几周前在我的工作电脑上安装了nodejs ...今天我已经尝试安装socket.io(通过npm install socket.io" on my stupid DOS terminal >_>),但我有一些代理问题然后我不能使用npm ...
可以Socket.io手动安装吗?或者我必须使用npm?
一如既往地为我糟糕的英语而烦恼
PS我的工作电脑SO是winXP
我已经研究猫鼬三天了,我对使用这两种方法感到有点困惑(我知道将来会弃用"mongoose.connection()"......)
问题是:当我尝试转换(从"mongoose.connection()"转换为"mongoose.createConnection()")此示例的action.js文件https://gist.github.com/2785463似乎不适合我......
这是我的代码......
var mongoose = require('mongoose'),
db = mongoose.createConnection('localhost', 'test');
db.on('error', function () {
console.log('Error! Database connection failed.');
});
db.once('open', function (argument) {
console.log('Database connection established!');
mongoose.connection.db.collectionNames(function (error, names) {
if (error) {
console.log('Error: '+ error);
} else {
console.log(names);
};
});
});
Run Code Online (Sandbox Code Playgroud)
并且有我的终端输出(在我的ubuntu终端上键入"node test.js"..)
Database connection established!
/home/_user_/Scrivania/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:437
throw err;
^
TypeError: Cannot call method 'collectionNames' of undefined
at NativeConnection.<anonymous> (/home/_user_/Scrivania/test2.js:11:25)
at NativeConnection.g (events.js:192:14)
at NativeConnection.EventEmitter.emit (events.js:93:17)
at open (/home/_user_/Scrivania/node_modules/mongoose/lib/connection.js:408:10)
at NativeConnection.Connection.onOpen (/home/_user_/Scrivania/node_modules/mongoose/lib/connection.js:415:5)
at Connection._open (/home/_user_/Scrivania/node_modules/mongoose/lib/connection.js:386:10) …Run Code Online (Sandbox Code Playgroud) 如果我想要一个按钮,但仅是它的演示部分,那么如果我这样做:
import styled from 'styled-components'
const Button = styled.button`
color: red;
text-align: center;
`
Run Code Online (Sandbox Code Playgroud)
我被迫渲染button标签,但是如果在语义上我需要锚点呢?
有一种方法可以编写键/值对列表吗?
我试过这个:
+ key1: value1
+ key2: value2
+ key3: value3
Run Code Online (Sandbox Code Playgroud)
但结果对我来说不是很干净..
我也试过桌子:
| | |
|----|------|
|key1|value1|
|key2|value2|
|key3|value3|
Run Code Online (Sandbox Code Playgroud)
但是表格不适用于键/值列表(例如我将标题行留空,这对我来说听起来很难看......)
我正在尝试将我的应用程序的节点版本从node6升级到node8.6,它本身支持spread运算符,一切正常,直到我尝试使用webpack编译我的节点脚本.
我已经创建了一个测试脚本(测试async/await的本机支持,适用于此场合):
const fs = require('fs')
const {promisify} = require('util')
const app = async () => {
try {
const todosString = await promisify(fs.readFile)('todos.txt', {
encoding: 'utf8',
})
return todosString
.split('\n')
.filter(Boolean)
.reduce((acc, val) => ({...acc, [val]: true}), {})
} catch (e) {
console.error('wooot', e)
}
}
app().then(console.log)
Run Code Online (Sandbox Code Playgroud)
这是webpack配置:
const path = require('path')
const nodeExternals = require('webpack-node-externals')
module.exports = {
entry: './index.js',
output: {filename: '[name].js'},
target: 'node',
externals: [nodeExternals()],
node: {
__dirname: true,
__filename: true,
},
module: {
rules: [ …Run Code Online (Sandbox Code Playgroud) 这是我的Coffescript Router类:
class App.Router extends Backbone.Router
initialize: ->
console.log 'Router.init'
@on 'all', ->
console.info 'route changed'
routes:
'': 'home'
'test': 'test'
home: ->
console.log 'home routed'
test: ->
console.log 'test routed'
Run Code Online (Sandbox Code Playgroud)
当我重新加载我的localhost页面时,"@ all'all'"回调似乎触发了两次(我的firebug上的double console.info ...)
这是我的firebug输出:
App.init
Session.init
Router.init
home routed
route changed
route changed
Run Code Online (Sandbox Code Playgroud)
正如您所看到的那样,"路径已更改"输出位于我的主路线之后......
最后这是我的引导代码(使用我的App命名空间......),我放置了history.start
App =
init: ->
console.log 'App.init'
@session = new App.Model.Session
@router = new App.Router
# @userPanel = new App.View.UserPanel
Backbone.history.start pushState: true
Model: {}
View: {}
Run Code Online (Sandbox Code Playgroud) 从Slim Framework文档中挑选:
模式
这是应用程序当前操作模式的标识符.该模式不会影响Slim应用程序的内部功能.相反,该模式仅供您使用configMode()应用程序方法为给定模式选择性地调用自己的代码.
应用程序模式在实例化期间声明,作为环境变量或作为Slim应用程序构造函数的参数.之后无法改变.模式可能是你想要的任何东西 - "开发","测试"和"生产"是典型的,但你可以自由地使用你想要的任何东西(例如"foo").
<?php
$app = new \Slim\Slim(array(
'mode' => 'development'
));
?>
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试调用$ app-> configMode(); 我得到一个致命的错误,他说configMode()方法是未定义的...
我是MySQL Workbench的新手,我真的不知道如何在MySQL Modeling面板上重命名SQL脚本......

我感觉有点傻了!
提前致谢!
这是我的注销点击事件:
logoutClicked: (event) ->
event.preventDefault()
console.log 'userPanel.logoutClicked -> event', event
console.info App.session
App.session.destroy
wait: true
success: (model, res) ->
console.log 'session.destroy.success -> model/res', model, res
error: (model, res) ->
console.log 'session.destroy.error -> model/res', model, res
Run Code Online (Sandbox Code Playgroud)
这是我的会话模型:
class App.Model.Session extends Backbone.Model
initialize: ->
console.log 'Session.init'
urlRoot: '/session'
Run Code Online (Sandbox Code Playgroud)
这是我纤细的后端路线:
$app->delete('/session', function () {
session_unset();
exit(true);
});
Run Code Online (Sandbox Code Playgroud)
当我触发logoutClicked事件时,一切正常,但我无法通过我的firebug看到任何服务器通信(没有DELETE或GET到/ session ...).
Firebug输出:
userPanel.logoutClicked -> event Object { originalEvent=Event click, type="click", timeStamp=18807379, altri elementi...}
Session { cid="c1", attributes={...}, _changing=false, altri elementi...}
session.destroy.success -> model/res Session …Run Code Online (Sandbox Code Playgroud) javascript ×8
node.js ×4
backbone.js ×2
coffeescript ×2
mongodb ×2
mongoose ×2
reactjs ×2
slim ×2
babeljs ×1
css ×1
express ×1
markdown ×1
php ×1
react-intl ×1
react-router ×1
redux ×1
regex ×1
rest ×1
socket.io ×1
webpack ×1