TLDR:使用defaultChecked而不是checked,在这里工作jsbin http://jsbin.com/mecimayawe/1/edit?js,output
尝试设置一个简单的复选框,在选中时会勾选其标签文本.出于某种原因,当我使用该组件时,handleChange不会被触发.谁能解释我做错了什么?
var CrossoutCheckbox = React.createClass({
getInitialState: function () {
return {
complete: (!!this.props.complete) || false
};
},
handleChange: function(){
console.log('handleChange', this.refs.complete.checked); // Never gets logged
this.setState({
complete: this.refs.complete.checked
});
},
render: function(){
var labelStyle={
'text-decoration': this.state.complete?'line-through':''
};
return (
<span>
<label style={labelStyle}>
<input
type="checkbox"
checked={this.state.complete}
ref="complete"
onChange={this.handleChange}
/>
{this.props.text}
</label>
</span>
);
}
});
Run Code Online (Sandbox Code Playgroud)
用法:
React.renderComponent(CrossoutCheckbox({text: "Text Text", complete: false}), mountNode);
Run Code Online (Sandbox Code Playgroud)
解:
使用checked不会让底层值发生变化(显然),因此不会调用onChange处理程序.切换到defaultChecked似乎解决了这个问题:
var CrossoutCheckbox = React.createClass({
getInitialState: function () {
return {
complete: (!!this.props.complete) || false
}; …Run Code Online (Sandbox Code Playgroud) 有没有办法从 Git 存储库中删除分支而不进行克隆或任何其他类型的本地副本?
基本上,我正在开发用于发布管道的仪表板,并且不想为了删除已部署的功能分支而在仪表板服务器上拥有任何工作项目的代码。
以防万一,我们使用 Atlassian Stash 而不是 Github。
我正在做类似的事情:
git branch -D ssh://git@repository.com/team/project/feature/deleteme
Run Code Online (Sandbox Code Playgroud)