我有这个组件.我想向我创建的每个listElement传递一个调用处理程序.如果我像下面这样做bind(this),它可以正常工作.问题是我在控制台中从React收到此警告:bind(): You are binding a component method to the component. React does this for you automatically in a high-performance way, so you can safely remove this call.
var MyList = React.createClass({
render: function () {
var listElements = this.props.myListValues.map(function (val) {
return (
<ListElement onCallHandler={this.props.parentsCallHandler} val={val} />
);
}.bind(this));
return (
<ul>
{listElements}
</ul>
);
}
});
Run Code Online (Sandbox Code Playgroud)
如果我不绑定它,我的孩子们不知道调用处理程序.我能做些什么不同的事情?
PS:
我知道解构分配,比如解释http://facebook.github.io/react/docs/transferring-props.html#transferring-with-...-in-jsx,但我不想使用Harmony.
我有以下React组件,我想在我的select-block中选择一个带有TestUtils的selectElements.我怎么做?
var selectElements = ["type_a", "type_b"];
var SelectElement = React.createClass({
render: function() {
return (
<option value={this.props.type}>{this.props.type}</option>
);
}
});
var MyForm = React.createClass({
handleSubmit: function(e) {
console.log("submitted");
},
render: function () {
var selectElements = this.props.availableTypes.map(function (type) {
return (
<SelectElement key={type} type={type} />
);
});
return (
<form role="form" onSubmit={this.handleSubmit}>
<select ref="type" name="type">
<option value="">-- Choose --</option>
{selectElements}
</select>
<input type="submit" value="Search"/>
</form>
);
}
});
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这样做了:
var myFormComponent = TestUtils.renderIntoDocument(<MyForm selectElements={selectElements} />);
var form = TestUtils.findRenderedDOMComponentWithTag(myFormComponent, 'form'); …Run Code Online (Sandbox Code Playgroud) 我正在制作一个表格,我需要收音机输入.如何在onSubmit函数中获取已检查的无线电输入,正确的方法是什么?
这是我的代码,我myRadioInput-variable在提交时包含选项A或选项B:
React.createClass({
handleSubmit: function() {
e.preventDefault();
var myTextInput = this.refs.myTextInput.getDOMNode().value.trim();
var myRadioInput = "How ?";
},
render: function() {
return (
<form onSubmit={this.handleSubmit}>
<input type="text" ref="myTextInput" />
<label>
<span>Option A</span>
<input type="radio" name="myRadioInput" value="Option A"/>
</label>
<label>
<span>Option B</span>
<input type="radio" name="myRadioInput" value="Option B"/>
</label>
<input type="submit" value="Submit this"/>
</form>
)
}
});
Run Code Online (Sandbox Code Playgroud) 我有dropwizard-application(0.7.0),我想运行集成测试.
我使用DropwizardAppRule设置了集成测试,如下所示:
@ClassRule
public static final DropwizardAppRule<MyAppConfiguration> RULE =
new DropwizardAppRule<MyAppConfiguration>(
MyApplication.class, Resources.getResource("testconfiguration.yml").getPath());
Run Code Online (Sandbox Code Playgroud)
当我尝试使用它运行以下测试时,它不起作用,因为我没有运行我的迁移.运行迁移的最佳方法是什么?
测试:
@Test
public void fooTest() {
Client client = new Client();
String root = String.format("http://localhost:%d/", RULE.getLocalPort());
URI uri = UriBuilder.fromUri(root).path("/users").build();
client.resource(uri).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(User.class, new LoginUserDTO("email@email.com", "password"));
}
Run Code Online (Sandbox Code Playgroud)
组态:
public class MyAppConfiguration extends Configuration {
@Valid
@NotNull
private DataSourceFactory database = new DataSourceFactory();
@JsonProperty("database")
public DataSourceFactory getDataSourceFactory() {
return database;
}
@JsonProperty("database")
public void setDataSourceFactory(DataSourceFactory dataSourceFactory) {
this.database = dataSourceFactory;
}
Run Code Online (Sandbox Code Playgroud)
}