小编vba*_*osh的帖子

在事件处理程序中获取对React组件的引用

我可以将我的事件处理程序附加到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)

reactjs

38
推荐指数
2
解决办法
3万
查看次数

有没有办法遍历由React构建的树?

我需要为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)

javascript reactjs

9
推荐指数
1
解决办法
1766
查看次数

在Vue.js中收听自定义事件

Vue.js适用于浏览器事件,如clickmousedown.但是根本不适用于自定义事件.这是代码:

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.但只有后来弹出.

CodePen

javascript vue.js

8
推荐指数
2
解决办法
2万
查看次数

如何在 NodeJS 中生成一个新进程并将 stderr 重定向到 stdout?

我需要在 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)

bash node.js

5
推荐指数
1
解决办法
3537
查看次数

PHP:返回对数组元素的引用

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)

php arrays

4
推荐指数
1
解决办法
6859
查看次数

NodeJS需要('./path/to/image/image.jpg')作为base64

有没有办法告诉你require,如果文件名结束,.jpg那么它应该返回它的base64编码版本?

var image = require('./logo.jpg');
console.log(image); // data:image/jpg;base64,/9j/4AAQSkZJRgABAgA...
Run Code Online (Sandbox Code Playgroud)

require node.js

4
推荐指数
1
解决办法
6044
查看次数

大约一天的工作后,卷曲errno = 6

两天前我注意到我们的服务器(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.

我重新启动了它现在正在工作......但我想明天我将不得不重新启动.

关于根本原因的任何想法?

php curl nginx

2
推荐指数
1
解决办法
627
查看次数

标签 统计

javascript ×2

node.js ×2

php ×2

reactjs ×2

arrays ×1

bash ×1

curl ×1

nginx ×1

require ×1

vue.js ×1