は私の呼び出しJSXコンポーネントで次を考える:Reactクラスに渡された 'data-'小道具の使い方は?
<CoolThing data-itemx="Corduroy" data-itemy="Pancakes" />
私は私のCoolThing
クラスでこれらの文字列を使用することができるようにしたいです。
class CoolThing extends Component {
getStyle() {
var itemx = this.props.data-itemx;
var itemy = this.props.data-itemy;
これは、データ文字列の代わりにNaN
を生成します。私はいくつか他のものを試してみた:console.log(this.props)
を実行
this.props.dataItemx // undefined
this.props.dataitemx // undefined
this.props.itemx // undefined
this.props.data.itemx // error accessing itemx of undefined
はdata-itemx
が存在することを示しているが、私はそれにアクセスすることはできません。
私は既にhttps://facebook.github.io/react/docs/dom-elements.htmlを読んでいますが、この作業を行う方法はまだ分かりません。
どうやってこれを行うのですか? brackets
表記法を使用した