[英]Redux-form, how to set the Field name to a dynamic string?
Redux-form is not allowing me to set the Field name to an integer as it requires a string... How can I set the redux-form Field name to something the API can then use to record the user's option selected per Talent. Redux-form不允许我将字段名称设置为整数,因为它需要一个字符串...如何将Redux-form字段名称设置为API可以用来记录每个人才选择的用户选项的内容。
<Field
name='talent_id[' + {field.talent_id} + ']'
component={renderField}
field={field}
/>
This is not working, I'm getting Syntax error: Unexpected token
with the +
这不起作用,我收到
Syntax error: Unexpected token
带有+
Syntax error: Unexpected token
Talents.rb 人才网
id | Title
1 | Jumping
2 | Skipping
3 | Running
My API, returns Talents#Index like so: 我的API,返回Talents#Index像这样:
[
{"id":1,"title":"Jumping"},
{"id":2,"title":"Skipping Rope"},
{"id":3,"title":"Running"},
{"id":4,"title":"Something Else"}
]
I then amusing the above to build a form that can later be submitted to the server. 然后,我通过以上内容来构建一个表单,以后可以将其提交到服务器。
<div>
<label>Jumping</label>
<select name="1">
<option></option>
<option value="1">XXX</option>
<option value="2">YYY</option>
<option value="3">ZZZ</option>
</select>
</div>
<div>
<label>Skipping Rope</label>
<select name="2">
<option></option>
<option value="1">XXX</option>
<option value="2">YYY</option>
<option value="3">ZZZ</option>
</select>
</div>
....
If you are use using ES5, simply like this: 如果您正在使用ES5,则就像这样:
<Field
name={`talent_id[${field.talent_id}]`}
component={renderField}
field={field}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.