我有一个表,我想在单击ADD按钮时向其添加一行.我怎么能用ReactJS代替简单的JavaScript?
码:
var RecordsComponent = React.createClass({
render : function() {
return (
<div>
<table>
<tr>
<td>row 1</td>
</tr>
<tr>
<td>row 2</td>
</tr>
<tr>
<td}>row 3</td>
</tr>
</table>
<button id="addBtn" onClick={addRow}>ADD</button>
</div>
);
},
addRow : function() {
//how to add row using ReactJS?
},
});
React.render(<RecordsComponent/>, document.getElementById('display'))
Run Code Online (Sandbox Code Playgroud) 我想使用 Bootstrap 在 ReactJS 中创建一个表。我已经编写了下面的代码并class="container"在 in<div>和class="table table-striped"in 中使用过,<table>但是引导程序在这段代码中不起作用。请告诉可能是什么问题?
应用程序.js
render : function() {
return (
<div class="container">
<table class="table table-striped">
<tbody>
{this.state.rows.map((r) => (
<tr>
<td>{r}</td>
<td>
<button onClick={() => this.deleteRow(r)}>Delete</button>
</td>
</tr>
))}
</tbody>
</table>
<input trype="text" id={"newVal"} onChange={this.updateNewValue}></input>
<button id="addBtn" onClick={this.addRow}>ADD</button>
</div>
);
},
Run Code Online (Sandbox Code Playgroud)
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sample Project</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootswatch/3.3.4/flatly/bootstrap.min.css" type="text/css" rel="stylesheet" />
<script src="app.js" type="text/babel"></script>
</head>
<body> …Run Code Online (Sandbox Code Playgroud) 我用C语言编写了一段代码,其中我用随机数字/字符初始化一个数组.但是当我在初始化之后打印数组值时,我看到每个索引上的值等于最后指定的值(最后一个索引的值).请告诉我代码中的问题是什么?
码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main () {
char *save[3][3] = { {" "," "," "}, {" "," "," "}, {" "," "," "} };
char x[2] = {'\0', '\0'};
int i, j, b;
srand(time(NULL));
printf("Assigned Values (initializing):\n");
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
b = rand()%10;
x[0] = b+'0';
save[i][j] = x;
printf("%s ",save[i][j]);
}
}
printf("\n\nValues after initializing:\n");
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
printf("%s ",save[i][j]);
}
}
printf("\n\n");
return …Run Code Online (Sandbox Code Playgroud)