如何在react.js 中利用for循环之类的输出html


请教以下这段代码用jsx 怎么写,主要是处理不好for 循环部分.
// 界面的拆分--------------------------------------------------------------------------------------------------


 getRowDraw : function() {
        var str = "";
        str = "<div  class=\"horizontal-line-container\"><div  class=\"horizontal-line-container2\">";
        for (var i = 0; i < 24; i++) {
            str += "<div style='height:"+(this.hourHeight-1)+"' class=\"horizontal-line\"><div style='height:"+(this.hourHeight/2-1)+"' ></div></div>";
        }
        str += "</div></div>";
        return str;
      };

react.js

千年组最高 9 years, 10 months ago

用es5的 forEach方法


 var arr = [...];
arr.forEach(function(value, index, array) {
    ...
})

RErush answered 9 years, 10 months ago

不要把react当成模板

6241794 answered 9 years, 10 months ago

最近刚学 react 的东西,还没看懂。

KSTTT answered 9 years, 10 months ago


 var doms = [];
for (var i = 0; i < 24; i++) {
  doms.push(<a>{i}</a>);
}
return doms;

我一般结合 underscore.js 的 map 方法:


 return _.map(persons, function (p) {
  return <div>{p.name} | {p.age}</div>;
});

LilMic answered 9 years, 10 months ago

Your Answer