我正在動態地創建大量元素。我有一個狀態數組,保持記錄的元素。當我添加更多的元素時,他們與之前的數組元素連接。這是代碼。我們如何在Reactjs中動態地刪除元素
var App = React.createClass({
getInitialState: function() {
return {
propsList: []
};
},
addProps: function(props) {
var propsList = this.state.propsList.concat([props]);
this.setState({ propsList: propsList });
},
render: function() {
var components = this.state.propsList.map(function(props) {
return React.createElement('g', props);
});
return React.createElement('div', null, components);
}
});
ReactDOM.render(
React.createElement(App, null),
document.getElementById('svg')
);
我想刪除執行單擊操作的元素(g
標記)。我試圖使用refs,但它沒有工作,因爲數組存儲太多元素。
檢查這一點,如果這可能有助於http://jsfiddle.net/fooey/t37Lk6p4/ – choz
這個分量i可以調用addProps以外()來傳遞的道具的陣列。 – Awais