我对React.JS还比较新,目前正在通过构建类似砌体样式的布局进行尝试。
我将每个元素渲染到DOM中,然后需要循环遍历每个项并根据前面的元素应用x和y位置。
初始模型如下:
[
{
"title": "The Forrest",
"description": "some cool text",
"imgSmallSrc": "/img/img4-small.jpg",
"imgAlt": "Placeholder image",
"tags": [
"Design",
"Mobile",
"Responsive"
],
"date": 1367154709885,
"podStyle": {
"width": 253
}
}
]
(为了简洁起见,我只展示了一个条目。)
循环结束并获得我的x和y数据后,我想将其应用于podStyle
对象。我使用以下数据调用setState()
:
[
{
"podStyle": {
"x": 0,
"y": 0,
"height": 146,
"width": 253
}
}
]
这似乎会从模型中删除所有当前数据,并只保留podStyle
数据。我是否误解了此合并的工作方式?