我定义了一个结构...
type Session struct {
playerId string
beehive string
timestamp time.Time
}
Run Code Online (Sandbox Code Playgroud)
有时我给它分配一个空会话(因为nil是不可能的)
session = Session{};
Run Code Online (Sandbox Code Playgroud)
然后我想检查,如果它是空的:
if session == Session{} {
// do stuff...
}
Run Code Online (Sandbox Code Playgroud)
显然这不起作用.我怎么写呢?
我想在React中的div上使用keyDown事件.我做:
componentWillMount() {
document.addEventListener("keydown", this.onKeyPressed.bind(this));
}
componentWillUnmount() {
document.removeEventListener("keydown", this.onKeyPressed.bind(this));
}
onKeyPressed(e) {
console.log(e.keyCode);
}
render() {
let player = this.props.boards.dungeons[this.props.boards.currentBoard].player;
return (
<div
className="player"
style={{ position: "absolute" }}
onKeyDown={this.onKeyPressed} // not working
>
<div className="light-circle">
<div className="image-wrapper">
<img src={IMG_URL+player.img} />
</div>
</div>
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我想在React风格中做得更多.我试过了
onKeyDown={this.onKeyPressed}
Run Code Online (Sandbox Code Playgroud)
在组件上.但它没有反应.我记得它适用于输入元素.
Codepen:http://codepen.io/lafisrap/pen/OmyBYG
我该怎么做?
我尝试遍历一个地图,我作为指向函数的指针传递,但我找不到访问元素的方法.这是代码:
func refreshSession(sessions *map[string]Session) {
now := time.Now()
for sid := range *sessions {
if now.After(*sessions[sid].timestamp.Add(sessionRefresh)) {
delete( *sessions, sid )
}
}
}
Run Code Online (Sandbox Code Playgroud)
此示例中的第4行返回以下编译错误:
./controller.go:120: invalid operation: sessions[sid] (type *map[string]Session does not support indexing)
Run Code Online (Sandbox Code Playgroud)
我试过括号,但没有效果.如果我带走所有引用运算符(*&),那么它编译得很好.
我该怎么写这个?
我正在使用github.com/go-sql-driver/mysql驱动程序.
我打开一个数据库:
db, err := sql.Open("mysql", str)
Run Code Online (Sandbox Code Playgroud)
然后我有两个函数,每个函数调用200次,每个函数使用以下mysql代码:
rows, err := db.Query("select name from beehives")
if err != nil {
panic(err)
}
defer rows.Close()
Run Code Online (Sandbox Code Playgroud)
第二:
err = db.QueryRow("select id, secret, shortname from beehives where shortname = ?", beehive).Scan(&id, &secre
switch {
case err == sql.ErrNoRows:
err = errors.New("Beehive '"+beehive+"' not found.")
case err != nil:
panic("loginBeehive: "+ err.Error())
default:
// ... do the work
Run Code Online (Sandbox Code Playgroud)
第一个是慌乱.
当我只打开一次数据库时,怎么会有多个连接?如何关闭它们?
目前,我在访问数据库的每个函数的开头使用以下命令.
o := orm.NewOrm()
o.Using("default") // Using default, you can use other database
Run Code Online (Sandbox Code Playgroud)
感觉就像我应该在路由器初始化时只做一次.这可能是一个安全问题吗?
我有一个内部开发设备,高度固定,overflow-y: scroll;可以在y方向上滚动内容。当滚动达到顶部或底部时,外部div滚动。我想防止这种情况。
<section id="concept" class="testimonials bg-black">
<div class="col-lg-12">
<div class="concept-frame">
</div>
</div>
</section>
Run Code Online (Sandbox Code Playgroud)
我使用以下JavaScript:
$( ".concept-frame" ).scroll( function(e) {
console.log( "Scolling ..."+$(this).scrollTop() );
e.stopPropagation();
} );
Run Code Online (Sandbox Code Playgroud)
但是没有效果。如何停止滚动传播到外部div?
我使用以下代码来显示自定义ttf字体:
ml.score = cc.LabelTTF.create(ml.totalPoints.toString(), "fonts/American Typewriter.ttf", 60);
ml.score.setPosition(ml.size.width/2,BS*0.6);
ml.score.retain();
ml.score.setColor(cc.color(200,160,70));
ml.scoreBar.addChild(ml.score, 5);
Run Code Online (Sandbox Code Playgroud)
在Android中,不显示字体.在Chrome/Firefox浏览器中它是.
我正在使用cocos2d-js 30RC.
笏?
我有一个nodejs API作为服务器,而React / Redux应用程序作为客户端位于一个git项目中:https : //github.com/lafisrap/fcc_nightlife.git
我想使用heroku cli在Heroku上部署它。
package.json中的脚本部分为:
"scripts": {
"start-dev": "concurrently \"yarn run server\" \"yarn run client\"",
"start": "yarn run server | yarn run client",
"server": "babel-node server.js",
"client": "node start-client.js",
"lint": "eslint ."
},
Run Code Online (Sandbox Code Playgroud)
start-client.js:
const args = [ 'start' ];
const opts = { stdio: 'inherit', cwd: 'client', shell: true };
require('child_process').spawn('yarn', args, opts);
Run Code Online (Sandbox Code Playgroud)
在客户端文件夹中,我还有另一个package.json,它定义了客户端。它的脚本部分:
"scripts": {
"start": "react-scripts start",
}
Run Code Online (Sandbox Code Playgroud)
我做了:
heroku创建
git push heroku master
api运行正常。但是我不知道如何启动/访问客户端。
我想将随机值读入字节数组.它的工作原理如下:
hash = make([]byte,20)
_, err := rand.Read(hash)
Run Code Online (Sandbox Code Playgroud)
但我想做点什么
var hash [20]byte
_, err := rand.Read(hash)
Run Code Online (Sandbox Code Playgroud)
这导致了
cannot use hash (type [20]byte) as type []byte in argument to "crypto/rand".Read
Run Code Online (Sandbox Code Playgroud)
如何在rand.Read中使用[20]字节?
我想加入两行,但是收到错误消息.
原版的:
hash := sha1.Sum([]byte(uf.Pwd))
u.Pwhash = hex.EncodeToString(hash[:])
Run Code Online (Sandbox Code Playgroud)
联合:
u.Pwhash = hex.EncodeToString(sha1.Sum([]byte(uf.Pwd))[:])
Run Code Online (Sandbox Code Playgroud)
第一个工作正常,第二个产生错误消息:
models/models.go:104: invalid operation sha1.Sum(([]byte)(uf.Pwd))[:] (slice of unaddressable value)
Run Code Online (Sandbox Code Playgroud)
这是为什么?
go ×6
android ×1
arrays ×1
beego ×1
client ×1
cocos2d-js ×1
cocos2d-x ×1
cryptography ×1
deployment ×1
dictionary ×1
events ×1
heroku ×1
html ×1
javascript ×1
jquery ×1
keydown ×1
keypress ×1
mysql ×1
node.js ×1
orm ×1
pointers ×1
random ×1
reactjs ×1
return-value ×1
scroll ×1
server ×1
slice ×1
struct ×1
variables ×1