Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
relyky committed Mar 19, 2019
1 parent 1d5e68f commit c4bb52a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mvcReduxLab/Areas/BS4/Views/TodoMVC/Default.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
}

<style type="text/css">
.rkm-hide-checkbox {
.kym-hide-checkbox {
text-align: center;
border: none;
opacity: 0;
Expand All @@ -21,7 +21,7 @@
<div class="input-group-prepend">
<div class="input-group-text">
<label class="form-check-label text-light" style="font-size:2em" title="Check all 若是全選顏色設為text-dark,否則為text-light">
<input type="checkbox" class="rkm-hide-checkbox" onclick="alert('check up 若是全選顏色設為text-dark,否則為text-light')">
<input type="checkbox" class="kym-hide-checkbox" onclick="alert('check up 若是全選顏色設為text-dark,否則為text-light')">
<i class="fa fa-check" aria-hidden="true"></i>
</label>
</div>
Expand All @@ -33,7 +33,7 @@
<ul class="list-group" style="font-size:2em">
<li class="list-group-item">
<label class="form-check-label text-black-50">
<input type="checkbox" class="rkm-hide-checkbox" onclick="alert('check up')">
<input type="checkbox" class="kym-hide-checkbox" onclick="alert('check up')">
<i class="fa fa-square-o" aria-hidden="true"></i>
</label>
<span class="form-control-static">完成方案第二版</span>
Expand All @@ -43,7 +43,7 @@
</li>
<li class="list-group-item">
<label class="form-check-label text-black-50">
<input type="checkbox" class="rkm-hide-checkbox" onclick="alert('check up')">
<input type="checkbox" class="kym-hide-checkbox" onclick="alert('check up')">
<i class="fa fa-check-square-o" aria-hidden="true"></i>
</label>
<span class="form-control-static"><s>到超市買蘋果</s></span>
Expand All @@ -53,7 +53,7 @@
</li>
<li class="list-group-item">
<label class="form-check-label text-black-50">
<input type="checkbox" class="rkm-hide-checkbox" onclick="alert('check up')">
<input type="checkbox" class="kym-hide-checkbox" onclick="alert('check up')">
<i class="fa fa-square-o" aria-hidden="true"></i>
</label>
<span class="form-control-static">到超商買哈蜜瓜</span>
Expand All @@ -63,7 +63,7 @@
</li>
<li class="list-group-item">
<label class="form-check-label text-black-50">
<input type="checkbox" class="rkm-hide-checkbox" onclick="alert('check up')">
<input type="checkbox" class="kym-hide-checkbox" onclick="alert('check up')">
<i class="fa fa-square-o" aria-hidden="true"></i>
</label>
<span class="form-control-static">晚上六點吃早餐</span>
Expand All @@ -73,7 +73,7 @@
</li>
<li class="list-group-item">
<label class="form-check-label text-black-50">
<input type="checkbox" class="rkm-hide-checkbox" onclick="alert('check up')">
<input type="checkbox" class="kym-hide-checkbox" onclick="alert('check up')">
<i class="fa fa-square-o" aria-hidden="true"></i>
</label>
<span class="form-control-static">交報告給老闆</span>
Expand Down
63 changes: 63 additions & 0 deletions mvcReduxLab/Scripts/React/ReduxLab/ReduxHello/InputMIrror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import actions, { Ks } from 'CommonFF/actions.js'

class InputMirror extends Component {
constructor(props) {
super(props)

this.handleInputChange = this.handleInputChange.bind(this)
}

render() {
const { hello } = this.props
return (
<div className="container">
<input name="hello"
value={hello}
onChange={this.handleInputChange}
/>
</div>
)
}

handleInputChange(e) {
const target = e.target
const value = target.type === 'checkbox' ? target.checked : target.value
const name = target.name

// 法1:
const action = { type: Ks.ASSIGN_VALUE, name, value }
this.props.dispatch(action)

// 法2:
this.props.dispatch(actions.assignValue(name, value))

// 法3: --- 過度包裝,除非有 高度共用性
this.props.handleValueChange(name, value)

// 法4: *** 回歸最原生的方法,反而是綜合考量後的最佳解
this.props.dispatch({ type: Ks.ASSIGN_VALUE, name, value })

//this.setState({
// [name]: value
//})
}

}

// connect to Store
const mapStateToProps = (state, ownProps) => ({
hello: state.helloInfo.hello
})

const targetReducer = 'helloReducer'
const mapDispatchToProps = (dispatch, ownProps) => ({
dispatch,
handleValueChange: (name, value) => dispatch({ type: Ks.ASSIGN_VALUE, name, value, targetReducer })
})

export default connect(
mapStateToProps,
mapDispatchToProps
)(InputMirror);

0 comments on commit c4bb52a

Please sign in to comment.