English 中文(简体)
复制件
原标题:React cloneNode - make a copy

可否在React中做一只 clo?

在基本层面,我想要做的是点击该构成部分,然后把该构成部分的副本交给我使用。 我最后想做简单的剪辑,然后倒掉,但我只想知道如何做部分/部分。

是否有更好的途径来实现这一目标? 该构成部分将固定不变,然后简单点击就会遮掩或动态制造供使用。

var TestChild = React.createClass({
    onClick: function (e) {
        this.props.onClick(e);
    },
    render: function () {
        return (
            <div onClick={this.onClick}>Test Item</div>
        )
    }
});

var TestParent = React.createClass({
    onClick: function (e) {
        // cloneNode
    },
    render: function () {
        return (
            <TestChild onClick={this.onClick} />
        )
    }
});
问题回答

关于在母体元素中保留国家的内容<代码> 试验,说明现在应当有多少儿童要素<编码> 试验,如<条码>。 页: 1 测试Childs。 <代码>onClick功能只是增加了反射。 http://facebook.github.io/react/docs/multiple-components.html#dynamic-children” rel=“nofollow”>example

我并不真正理解你想要做些什么,而是指你的儿童部分,然后使用cloneElement(),就是这样。

var TestChild = React.createClass({
    onClick: function (e) {
        this.props.onClick(e);
    },
    render: function () {
        return (
            <div onClick={this.onClick}>Test Item</div>
        )
    }
});

var TestParent = React.createClass({
    onClick: function (e) {
        const newEl = React.cloneElement(this.myRef, {});
        // then you do whatever you need to do with your new copy of TestChild component
    },
    render: function () {
        return (
            <TestChild onClick={this.onClick} ref={this.myRef} />
        )
    }
});

能否得到这种帮助?





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签