将react js组件拆分为单独的文件——并处理基于仪表板的应用程序的创建
Splitting up react js components into separate files -- and handling the creation of a dashboard based application
我正在考虑使用reactjs作为一个框架来管理/控制各种图表小部件。
—当我开始寻找将这些组件放入单独的js文件时—未定义的错误开始出现。
—然后如何构建图表应该如何在面板上呈现,如何实现交互—主/从关系—更新cta
http://jsfiddle.net/cfrapLma/28/var config = [{
"width": 200,
"height": 200,
"type": "piechart",
"serviceApi": "api.php?mode=GetCars"
}, {
"width": 100,
"height": 100,
"type": "barchart",
"serviceApi": "api.php?mode=GetBoats"
},
{
"width": 200,
"height": 200,
"type": "piechart",
"serviceApi": "api.php?mode=GetCars"
},
{
"width": 200,
"height": 200,
"type": "linechart",
"serviceApi": "api.php?mode=GetCars"
}];
var MultipleCharts = React.createClass({
getChart: function(config) {
switch (config.type) {
case 'piechart':
return <PieChart width={config.width} height={config.height} service={config.service} />
case 'barchart':
return <BarChart width={config.width} height={config.height} service={config.service} />
case 'linechart':
return <LineChart width={config.width} height={config.height} service={config.service} />
}
},
render: function () {
var config = this.props.config;
return (
<div>
{config.map((chartConfig, index) => {
return (
<div key={index} className={'holder' + index}>
{this.getChart(chartConfig)}
</div>
)
})}
</div>
);
}
});
var PieChart = React.createClass({
componentDidMount: function () {
var $this = $(ReactDOM.findDOMNode(this));
console.log("rendered div now engage d3");
// set el height and width etc.
},
render: function () {
return (
<div className="piechart" data-role="piechart" data-width={this.props.width} data-height={this.props.height}
data-service={this.props.service}>pie.
</div>
);
}
});
var LineChart = React.createClass({
componentDidMount: function () {
var $this = $(ReactDOM.findDOMNode(this));
console.log("rendered div now engage d3");
// set el height and width etc.
},
render: function () {
return (
<div className="linechart" data-role="linechart" data-width={this.props.width} data-height={this.props.height}
data-service={this.props.service}>line.
</div>
);
}
});
var BarChart = React.createClass({
componentDidMount: function () {
var $this = $(ReactDOM.findDOMNode(this));
console.log("rendered div now engage d3");
// set el height and width etc.
},
render: function () {
return (
<div className="barchart" data-role="barchart" data-width={this.props.width} data-height={this.props.height}
data-service={this.props.service}>bar.
</div>
);
}
});
ReactDOM.render(
<MultipleCharts config={config} />,
document.getElementById('example')
);
您应该使用一些构建工具,如webpack或gulp。我提供了一个你应该如何做的例子。
https://github.com/OnlyRefat/Example它将帮助你编写模块代码。
相关文章:
- 有没有一种方法可以让内联事件处理程序在元素创建后立即执行
- sailsjs在创建两个模型时的错误处理
- .on(“单击”,..)不处理使用相同的单击功能创建的对象
- 为主题选项(部分)创建一个ajax处理的保存操作
- 在动态创建的元素中包含参数的事件处理程序
- 在服务器上创建一个复选框,使用 javascript 处理函数
- 创建一个简单的处理 p5.js 库
- 处理由无法访问的代码创建的来自Webworker的消息
- InnerHTML创建问题,没有't加载顺序正确,可能存在处理问题
- 如何从控制器创建进度条来处理MVC3中的长流程
- 在Meteor中,我如何创建一个通用的事件处理程序
- 如何使用onClick处理程序在React组件中创建链接
- AngularJS-由$scope创建的作用域何时执行$new()已删除.垃圾收集器或Angular负责处理它吗
- 在javascript上创建,以处理单击后要隐藏的几个单选按钮
- 在Meteor中,我如何创建一个跨所有模板工作的通用事件处理程序
- 警告:在处理程序中创建了promise,但未从中返回
- Does underscore.js在_中创建匿名func对象,每个对象都需要进行乱码处理
- 使用运行时创建的链接来触发ASP.Net中隐藏按钮的单击处理程序
- 对象是't可在同一html画布元素上处理和创建fabric画布后选择
- 为延迟请求处理创建承诺链