I want to leave the dynamically disabled / disabled attribute on a button element. I have seen many examples of dynamic attribute values, but not the qualities of oneself. I have the following renderer functions:
render: function () {var may be displayed = appstore curtispte ()? "Disabled": ""; Return & lt; Button {possibly deleted} & gt; Clean Cart & lt; / Button & gt; }
This throws a parse error due to the character "{". How can I include / exclude the disabled attribute based on the (boolean) result of AppStore.cartIsEmpty ()?
Optional attributes ( disabled
and others you want to use) The best way to add is currently to use it:
var hello = response .createclass ({render: function () {var opts = {}; if (this.props. Disabled) {opts ['disabled'] = 'disabled';} Return & lt; button {... opts}> Hello {this.props .name} & lt; / button & gt;;}}); React.render ((& lt; div & gt; Hello name = "disabled" disabled = 'true' /> & lt; hello name = "enabled" /> gt; Document.getElementById ('container'));
By using spread attributes, you can dynamically add (or override) whatever you want using the JavaScript Object Insertion. In your example above, the code creates the code disabled
key (with the disabled
value in this code) when disabled
property greeting
Component example
If you want to use only disabled
, then the answer works well.
No comments:
Post a Comment