繼後反應JS顯示的數據是我的反應,它接受JSON格式的數據,並打印提交
var DataInTableFormat = React.createClass({
getInitialState: function() {
return {
phpData: [] //initial value
};//getInitialState
},//DataInTableFormat
componentDidMount: function() {
$.get(this.props.source, function(result) { //storing the JSON data in result
var collection = JSON.parse(result); //coverting JSON data to Javascript object
console.log(collection);
if (this.isMounted()) {//checking for component mount
this.setState({
phpData: collection
});
}
}.bind(this));
},
render:function()
{
DBdata = this.state.phpData || [];
return (
<form>
<div>Select ID :
<select>
{DBdata.map(function(d){
return(
<option value={d.id}>{d.id}</option>//prints the all id from the jsondata.php
)}
)}
</select>
<button name="submit">submit</button>
</div>
</form>
)}
});
React.render(
<DataInTableFormat source="http://localhost/PHP-React-Demo/jsondata.php" />,
document.getElementById('Table-data')
);
當我選擇的ID我只是想點擊後打印的表格形式的所有細節代碼提交。
您想要打印的數據取決於該ID您選擇? – vistajess
@bignose是..我要打印數據取決於我選擇的 – Param