0
フォーム上に選択(別名選択リスト)フィールドがあります。その値に基づいて、次のフィールド(従属フィールド)に影響します。これは、別の選択、入力タイプのテキスト、または無効な入力のいずれかです。条件付きフォーム要素をレンダリングする
擬似コード
// based on a state value, leadField, determine valueField
// if leadField === null, return a disabled input
// else, go through the array of leadField values
// if a leadFieldValue === leadField
// then go through leadFieldValue
// if leadFieldValue.pickListValues is not empty
// render the select options
// else render an input type text
コード
renderValueField() {
if(this.state.leadField === null) {
return <input type="text" id="input1" className="slds-input" disable/>
} else {
return this.props.territoryCriteriaFields.map((criteriaField) => {
const shouldRender = criteriaField.name === this.state.leadField;
if (shouldRender) {
if (typeof criteriaField.pickListValues !== 'undefined' && criteriaField.pickListValues.length > 0) {
return criteriaField.picklistValues.map((option) => {
return (
<option value={option.value}>{option.label}</option>
);
});
} else {
return <input type="text" id="input1" className="slds-input" />
}
}
});
}
}
私の問題:私はページ上の上記{this.renderValueField}
を呼び出すとき、それはとても
<select>
の とき
pickListValues !== null
の間にする必要があります
<select>
{this.renderValueField()}
</select>
しかし、入力がレンダリングされた場合には、<selects>
がそこに存在しないようにする必要があります。
TL; DR - 条件付きの戻り値に応じて、<select>
タグを削除、追加、私のrenderValueField()
() '関数を呼び出し、' var rVF = this.renderValueField(); 'を呼び出してその値をチェックし、' 'などを返します。 –
@ChrisG戻り値を比較するにはどうすればよいですか? –