我可以将我的事件处理程序附加到React组件.有没有办法在事件处理程序中获取对此组件的引用?
var Foobar = React.createClass({
action: function () {
// ...
},
render: function () {
var child = React.Children.only(this.props.children),
props = _.omit(this.props, 'children');
return React.addons.cloneWithProps(child, props);
}
});
var App = React.createClass({
handleMouseEnter: function (event) {
// How to get reference to Foobar without using this.refs['foo']?
// I need to call *action* on it.
},
render: function () {
return (
<div>
<Foobar ref="foo" onMouseEnter={this.handleMouseEnter}>
...
</Foobar>
</div>
);
}
});
Run Code Online (Sandbox Code Playgroud) 我需要为HTML页面构建一个可视化编辑器.似乎ReactJS是不错的选择.目前我面临以下问题:
我模拟了我的数据:
var Model = {
title: 'Hello',
description: 'Pellentesque eleifend urna ac purus tempus...',
date: new Date().toString()
};
Run Code Online (Sandbox Code Playgroud)
并构建了将其数据存储在上述结构中的组件:
var App = React.createClass({
getInitialState: function () {
return {
value: Model
}
},
handleMouseEnter: function (event) {
$(event.target).css('outline', '1px solid red').attr('contenteditable', true);
},
handleMouseLeave: function (event) {
var t = $(event.target), v = this.state.value;
t.css('outline', 'none').attr('contenteditable', false);
v[t.attr('property')] = t.text();
this.setState({value: v});
},
render: function () {
var v = this.state.value;
return (
<div>
<pre style={{whiteSpace: 'normal'}}>{JSON.stringify(this.state)}</pre>
<h1 onMouseEnter={this.handleMouseEnter} …Run Code Online (Sandbox Code Playgroud) Vue.js适用于浏览器事件,如click或mousedown.但是根本不适用于自定义事件.这是代码:
HTML:
<div id="app" style="display: none" v-show="true">
<div v-el:ping v-on:ping="ping">
<div>
<button v-on:click="click">Click</button>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
new Vue({
el: '#app',
data: {
},
methods: {
ping: function (event) {
console.log('Vue ping', event);
alert('Vue ping');
},
click: function (event) {
jQuery(event.target).trigger('ping');
}
},
ready: function () {
console.log(this.$els);
jQuery(this.$els.ping).on('ping', function (event) {
console.log('jQuery ping', event);
alert('jQuery ping');
});
}
});
Run Code Online (Sandbox Code Playgroud)
我希望Vue ping和他一起警惕jQuery ping.但只有后来弹出.
我需要在 NodeJS 中生成一个新进程。它的 stderr 应该被重定向到它的 stdout(与2>&1bash 中的一样)。
程序.js
var child_process = require('child_process');
var opt = {stdio: ['ignore', 'pipe', 'pipe']};
var proc = child_process.spawn('./myscript', [], opt);
proc.stderr.pipe(proc.stdout);
proc.stdout.on('data', function (buf) {
console.log('stdout', buf.toString());
});
proc.on('error', function (...args) {
console.log('error', args);
});
proc.on('exit', function (code, signal) {
console.log('exit', code, signal);
});
proc.on('close', function (code, signal) {
console.log('close', code, signal);
});
Run Code Online (Sandbox Code Playgroud)
我的脚本
#!/bin/bash
echo 111
echo 222 >&1
echo 333 >&2
echo 444
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用。输出中没有333:
stdout 111
222
444
exit …Run Code Online (Sandbox Code Playgroud) PHP中是否有一种方法可以返回对数组中元素的引用?
function ref(&$array, &$ref) { $ref = $array[1]; }
$array = array(00, 11, 22, 33, 44, 55, 66, 77, 88, 99);
ref($array, $ref);
$ref = 'xxxxxxxxxx';
var_dump($ref);
var_dump($array);
Run Code Online (Sandbox Code Playgroud)
我希望$ array会被更改,如下面的代码所示:
$array = array(00, 11, 22, 33, 44, 55, 66, 77, 88, 99);
$ref = &$array[1];
$ref = 'xxxxxxxxxx';
var_dump($ref);
var_dump($array);
Run Code Online (Sandbox Code Playgroud) 有没有办法告诉你require,如果文件名结束,.jpg那么它应该返回它的base64编码版本?
var image = require('./logo.jpg');
console.log(image); // data:image/jpg;base64,/9j/4AAQSkZJRgABAgA...
Run Code Online (Sandbox Code Playgroud) 两天前我注意到我们的服务器(nginx + php-fpm)停止工作,因为curl函数启动返回CURLE_COULDNT_RESOLVE_HOST.重新启动后,每次重新开始工作.但现在,经过大约一天的工作,我注意到了同样的错误.
当我ssh到服务器$ wget http://example.com正在工作.我也可以从php运行cli 请求http://example.com.但是当我尝试在Web服务器中从php 卷曲http://example.com时,我得到了CURLE_COULDNT_RESOLVE_HOST.
我重新启动了它现在正在工作......但我想明天我将不得不重新启动.
关于根本原因的任何想法?