【发布时间】:2016-02-04 06:00:18
【问题描述】:
我正在使用react-autosuggest component,并且我正在使用根据用户输入而变化的反应内联样式来设置其输入部分的边框。但是,尽管每次调用 render() 时都会将新样式传递给 Autosuggest 组件,但它并没有更新。这是我所拥有的:
var borderStyle;
if (gradient) {
borderStyle = {
borderImageSlice: 1,
borderImage: '-webkit-linear-gradient(right, '+borderColour2+' 0%, '+borderColour2+' 40%, '+borderColour1+' 60%, '+borderColour1+' 100%) 1'
};
}
else {
borderStyle = {
'borderColor': borderColour1
};
}
var theme = {
container: 'react-autosuggest__container',
containerOpen: 'react-autosuggest__container--open',
input: borderStyle,
suggestionsContainer: 'react-autosuggest__suggestions-container',
suggestion: 'react-autosuggest__suggestion',
suggestionFocused: 'react-autosuggest__suggestion--focused',
sectionContainer: 'react-autosuggest__section-container',
sectionTitle: 'react-autosuggest__section-title',
sectionSuggestionsContainer: 'react-autosuggest__section-suggestions-container'
};
<Autosuggest suggestions={suggestions}
theme={theme}
onSuggestionsUpdateRequested={this.onSuggestionsUpdateRequested}
getSuggestionValue={getSuggestionValue}
renderSuggestion={renderSuggestion}
inputProps={inputProps}
ref={this.saveInput}
onSuggestionSelected={this.selectCard} />
theme 时会更新,因此当 theme 传递到要渲染的组件时。
【问题讨论】:
标签: javascript css reactjs