我想创建一个随机随机播放一些动画的列表。反应:在列表混洗的连续呈现中会发生什么?
这里是the fiddle对于它我用key
道具来识别每个孩子。
var ListAnimate = React.createClass({
list: [
{id: 1, caption: "Hello"},
{id: 2, caption: "There"},
{id: 3, caption: "Whatsup"},
{id: 4, caption: "Sanket"},
{id: 5, caption: "Sahu"},
],
shuffle: function() {
this.list.shuffle(); // Shuffles array!
this.forceUpdate();
},
render: function() {
return <div>
<button onClick={this.shuffle}>Shuffle</button>
<ul>
{this.list.map(function(el, i){
return <li key={el.id} style={ {top: (i*60)+'px'} }>{el.caption} {el.id}</li>;
})}
</ul>
</div>;
}
});
React.render(<ListAnimate />, document.body);
从React docs about Dynamic Children,它指出key
支柱,以便在连续呈现,以确定在数组中的元素使用。因此,刚刚重新排序的项目不能卸载并安装到新的位置,而应该重新定位,但似乎并不在小提琴中发生,其中列表顶部的节点总是未安装并安装在不同的位置。
但是对于底部的元素似乎与动画效果很好。
当您完成更改时,您需要点击小提琴中的小提琴。链接只是去你好世界小提琴。此外,您需要在问题中包含小提琴中的代码,以防jsfiddle消失。 – FakeRainBrigand 2014-12-13 08:59:57
对不起,现在更新! (y) – 2014-12-13 09:11:07