ReactJS基于Object设置动态输入值

时间:2016-11-25 12:49:22

标签: javascript object reactjs react-jsx jsx

我有一个像这样的对象:

enter image description here

这样的对象:

const subjectQuantities = {
      9: 2,
      11: 1,
    };

其中9和11类似于第一个id的对象Object,我想要做的是动态设置输入字段的值,所以我做的是:

{ Object.keys(subjects).map((item, i) => (
   <li className="travelcompany-input clearfix" key={i}>
      <span className="input-label">{ subjects[item].name }</span>
         <div className="input-group">
           { subjects[item].id in subjectQuantities ?
            <input className="form-control form-travelcompany-input" type="text" value=*DYNAMIC VALUE* min="0" max="10" />
             : <p>TEST</p>
             }
         </div>
   </li>
))} 

如何根据subjectQuantities对象的值动态设置此输入字段的值。

1 个答案:

答案 0 :(得分:1)

如果我正确理解您的问题,您只需要执行WITH [Sample] AS ( -- CTE provides sample data. SELECT * FROM ( VALUES (1, 1, 3), (2, 1, 3), (3, 1, 3), (4, 1, 3), (5, 1, 3), (6, 1, 3), (7, 1, 3), (8, 1, 3), (9, 1, 3), (10, 2, 2), (11, 2, 2), (12, 2, 2), (13, 2, 2), (14, 2, 2), (15, 2, 2), (16, 2, 2) ) AS x(id, [type], periodicity) ) SELECT s.id, s.[type], s.periodicity, CASE ROW_NUMBER() OVER (PARTITION BY s.[type] ORDER BY s.id) % periodicity WHEN 1 THEN 1 ELSE 0 END AS execute_operation FROM [Sample] AS s ORDER BY s.id ;

请参阅下面的示例。

{subjectQuantities[item]}