Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在条件中基于条件呈现事物_Javascript_Html_Typescript - Fatal编程技术网

Javascript 在条件中基于条件呈现事物

Javascript 在条件中基于条件呈现事物,javascript,html,typescript,Javascript,Html,Typescript,因此,我试图实现@pnp/sp的占位符组件: public render(): React.ReactElement<Props> { let buttons; if (this.props.context.pageContext.web.permissions.hasPermission(SPPermission.addListItems)) { buttons = <div> <PrimaryButto

因此,我试图实现
@pnp/sp
占位符组件:

public render(): React.ReactElement<Props> { 
    let buttons;

    if (this.props.context.pageContext.web.permissions.hasPermission(SPPermission.addListItems)) {
        buttons = <div>
            <PrimaryButton 
                onClick={this._fetchJobs.bind(this)} text="Refresh Jobs" 
            />
            <PrimaryButton 
                onClick={this._showCreateJobPanel.bind(this)} 
                text="Create New Job" 
            />
        </div>;
    }

    return (
        <div className= { styles.container }>
            { this.state.locations ? (
                <Placeholder
                iconName='Edit'
                iconText="Configure the Delivery Board"
                description="Please configure your Delivery Board"
                buttonLabel="Configure"
                // onConfigure={this.props.fPropertyPaneOpen} />
                />                      
            ) : (
                <WebPartTitle
                displayMode={this.props.displayMode}
                title={this.props.title}
                updateProperty={this.props.updateProperty}
                />      

                {buttons} <-- line 216
            )}
        </div>
    )

}

我很确定它必须用嵌套的括号{}来处理,但我不知道为什么或者如何解决它。

在三元运算符的每种情况下只能放一个表达式。假设您使用的是react 16或更高版本,您可以通过将其包装在片段中来解决此问题:

{ this.state.locations ? (
  <Placeholder
  iconName='Edit'
  iconText="Configure the Delivery Board"
  description="Please configure your Delivery Board"
  buttonLabel="Configure"
  />                      
) : (
  <React.Fragment>
    <WebPartTitle
    displayMode={this.props.displayMode}
    title={this.props.title}
    updateProperty={this.props.updateProperty}
    />      
    {buttons}
  </React.Fragment>
)}
{this.state.locations(
) : (
{按钮}
)}
在react 16之前,您可以使用div,也可以使用数组。这是一个数组:

{ this.state.locations ? (
  <Placeholder
  iconName='Edit'
  iconText="Configure the Delivery Board"
  description="Please configure your Delivery Board"
  buttonLabel="Configure"
  />                      
) : (
  [
    <WebPartTitle
      displayMode={this.props.displayMode}
      title={this.props.title}
      updateProperty={this.props.updateProperty}
    />,
    buttons
  ]
)}
{this.state.locations(
) : (
[
,
按钮
]
)}

在三元运算符的每种情况下,只能放置一个表达式。假设您使用的是react 16或更高版本,您可以通过将其包装在片段中来解决此问题:

{ this.state.locations ? (
  <Placeholder
  iconName='Edit'
  iconText="Configure the Delivery Board"
  description="Please configure your Delivery Board"
  buttonLabel="Configure"
  />                      
) : (
  <React.Fragment>
    <WebPartTitle
    displayMode={this.props.displayMode}
    title={this.props.title}
    updateProperty={this.props.updateProperty}
    />      
    {buttons}
  </React.Fragment>
)}
{this.state.locations(
) : (
{按钮}
)}
在react 16之前,您可以使用div,也可以使用数组。这是一个数组:

{ this.state.locations ? (
  <Placeholder
  iconName='Edit'
  iconText="Configure the Delivery Board"
  description="Please configure your Delivery Board"
  buttonLabel="Configure"
  />                      
) : (
  [
    <WebPartTitle
      displayMode={this.props.displayMode}
      title={this.props.title}
      updateProperty={this.props.updateProperty}
    />,
    buttons
  ]
)}
{this.state.locations(
) : (
[
,
按钮
]
)}