[英]Send object as attributes to react component
I have the following Object我有以下对象
"RENDEROPTIONS":{
"TYPE_NAME":{
"single":true,
"urlParams":{
"ENTITYFIELD":"testt",
"USERID":1
},
"labelClass":"control-label",
"infiniteScrolling":true,
"naDesc":"--Select--",
"class":" entityParamsSelect",
"value":"",
"entityFieldRestrictions":false,
"name":"eval_type_id",
"validations":"required",
"selectValues":"",
"renderType":"select",
"label":" Type",
"keyField":"key",
"selectDescriptions":"",
"id":"eval_type_id",
"descField":"value",
"readOnly":false
}
and i want to send it as attributes to my react component.I tied to do it like this我想将它作为属性发送到我的反应组件。我像这样做
<div>
<entity-render-field
<% _.each(renderOptions["TYPE_NAME"], function(value, key) { %>
<% if (typeof(value) !=="object") {%>
<%= key%> = "<%=value%>"
<% } %>
<% if (typeof(value) ==="object") {%>
<%= key%> = <%=JSON.parse(JSON.stringify(value))%>
<% } %>
<% });%>
>
</entity-render-field>
</div>
but in the props the utlParams come as "[object" or ""[object", "object]" if i don't use the JSON.parse(JSON.stringify(value).Is there any way to send object as attributes to react component?但是在道具中,如果我不使用 JSON.parse(JSON.stringify(value),则 utlParams 将作为“[object”或“”[object”,“object]”出现。有没有办法将对象作为属性发送反应组件?
it is simple:很简单:
const RENDEROPTIONS = {
TYPE_NAME: {
single: true,
urlParams: {
ENTITYFIELD: "testt",
USERID: 1
},
labelClass: "control-label",
infiniteScrolling: true,
naDesc: "--Select--",
class: " entityParamsSelect",
value: "",
entityFieldRestrictions: false,
name: "eval_type_id",
validations: "required",
selectValues: "",
renderType: "select",
label: " Type",
keyField: "key",
selectDescriptions: "",
id: "eval_type_id",
descField: "value",
readOnly: false
}
};
const Child = ({ obj }) => {
console.log(obj);
return (
<div>
<h1>Child</h1>
</div>
);
const App = () => {
return (
<div className="App">
<Child obj={RENDEROPTIONS} />
</div>
);
};
export default App;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.