简体   繁体   English

如何使用React.js而不是JQuery.js克隆React组件(以附加到其他地方)

[英]How to clone a React Component (to append somewhere else) using React.js instead of JQuery.js

I am working on some fieldsets using React.js + Backbone.js. 我正在使用React.js + Backbone.js处理一些字段集。

I have a table containing many columns and rows. 我有一个包含许多列和行的表。 Task is to make first column fixed whenever number of columns are greater than to show on screen. 任务是在列数大于屏幕上显示的列时固定第一列。 (eg total columns are 8, only 6 columns can be shown on screen) So other two can be seen by scrolling horizontally. (例如,总列数为8,屏幕上只能显示6列)因此可以通过水平滚动查看其他两列。

With the logic currently I am is, use jQuery to clone each first column of each row, and create a new table, then append it after the original table, use CSS to position it on the original table, so the user can see the first column is fixed. 使用我现在的逻辑,使用jQuery克隆每一行的每个第一列,并创建一个新表,然后将其附加到原始表之后,使用CSS将其定位在原始表上,这样用户就可以看到第一列列是固定的。

I am not satisfy with this approach, need your help to do great with great Virtual DOM of great Reactjs :) Any idea, suggestion will be appreciable :) 我不满足于这种方法,需要你的帮助,以伟大的Reactjs伟大的虚拟DOM做得很好:)任何想法,建议将是可观的:)

start with simple react Table component: 从简单的反应表组件开始:

var Table= React.createClass({
    render: function() {
        return <table>
            {this.props.data.map(function(row){
                return <tr>
                    {row.map(function(cell){
                        return <td> {cell} </td>
                    })}
                </tr>
            })}
        </table>;
    }
});

this components is just a demo, real life table should be more complex. 这个组件只是一个演示,现实生活表应该更复杂。

now, the table you want is this component: 现在,你想要的表是这个组件:

var DubbledTable= React.createClass({
    render: function() {
        var firstColumn= 
            this.props.data.map(function(row){
                return [row[0]]
            })
        return <span>
            <Table data={firstColumn} />
            <Table data={this.props.data} />
        </span>
    }
})

demo- http://jsfiddle.net/psx9f644/ 演示 - http://jsfiddle.net/psx9f644/

enjoy 请享用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM