2016-12-20 7 views
0

は、私が「テーブル」のリストをレンダリングし、このコード現在のIDをデータに渡すにはどうすれば反応するのですか?

var html = []; 
    for (var i = 0, len = this.props.tables.length; i < len; i++) { 

     var id = this.props.tables[i]._id;//._str; 
     html.push(
      <div key={id} className="col-xs-6 col-md-3"> 
       <div className={"thumbnail " + cls}> 
        <div> 
         <a role="button" className="btn btn-danger glyphicon glyphicon-trash" 
          onClick={() => { this.deleteTable(id) } } /> 
        </div> 
       </div> 
      </div>); 
    } 

を持っている、と私はid与えられたデータを削除した関数を呼び出しています。しかし、私が渡しているIDは別の "テーブル"(最後のもの、いつも)を削除してしまうので、何とか削除ボタンでIDをどうにか保存する必要があります。それ、どうやったら出来るの?

(私はthis.props.tables[i]._idを渡すために使用されるが、それはそれは、最新のiを見ていたので、this.props.tables[i]が未定義であることを私に言った)、

これは、流星と反応しています。

+0

あなたのdeleteTableコードを共有できますか? –

+0

ちょうど deleteTable(id){ Meteor.call( 'tables.deleteTable'、id); } ここで、流行関数は 'Tables.remove(id);'を実行し、テーブルは 'export const Tables = new Mongo.Collection( 'tables');' – adinutzyc21

答えて

0

新しいクラスTableDeleteを作成し、そのIDをパラメータとして渡すことで、私はそれを回避しました。 ので、代わり<a\>の私はTableDeleteは基本的に

/** 
* Delete a row from the Tables collection, given its id 
* @param id the id of the column 
*/ 
deleteTable(id) { 
    Meteor.call('tables.removeTable', id); 
} 

/** 
* Display the delete button based on the parameters 
*/ 
render() { 
    // set the callback depending on the type of delete (row/col) 
    var callback = this.deleteTable; //row 
    var title = 'Delete Table'; 

    // display the button 
    return (
     <a role="button" data-toggle="tooltip" title={title} 
      className={'btn btn-danger glyphicon glyphicon-trash'} 
      onClick={() => { callback(this.props.params); } } > 
     </a> 
    ); 
} 

であるとし、paramsが

/** 
* params: parameters to callback function 
*/ 
TableDelete.propTypes = { 
    params: PropTypes.object.isRequired 
}; 

ている私は、これがうまくいく理由はまだ分からないが、上記のこと

<TableDelete key="del" params={this.props.tables[i]._id} /> 

を持っていますあなたは...

関連する問題