Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.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_Reactjs_React Native - Fatal编程技术网

Javascript 基于属性传递属性并给出警告

Javascript 基于属性传递属性并给出警告,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我这样调用组件 <SearchableList pullToRefresh="" items={groupStates} searchFields={groupStateSearchFields} searchTemplate={() => <GroupStateSearchEntry />} itemTemplate={x => <GroupStateItem key={x.groupName} groupState=

我这样调用
组件

<SearchableList
    pullToRefresh=""
    items={groupStates}
    searchFields={groupStateSearchFields}
    searchTemplate={() => <GroupStateSearchEntry />}
    itemTemplate={x => <GroupStateItem key={x.groupName} groupState={x} />} />
<SearchableList
    items={items}
    searchFields={searchFields}
    searchTemplate={() => <SearchEntry />}
    pullToRefresh="conversations"
    itemTemplate={item => <ConversationItem key={item.id} item={item}
        isSelected={this.state.isArchiving && this.state.selectedConversations.indexOf(item.id) >= 0}
        onPressItem={this.pressItem} onLongPressItem={this.longPressItem} accountTimeZone={this.store.accountTimeZone} />} />
<ScrollView 
    ref={(ref) => this._refScrollView = ref}
    onContentSizeChange={this.scrollToEnd}
    refreshControl={
        (pullToRefresh == 'conversations') &&
        <RefreshControl
            refreshing={this.state.refreshing}
            onRefresh={this._onRefresh.bind(this)}
        />
}>
    {!this.state.isBusy && !this.state.items.length && (
        <View>
            {!!blankItemTemplate && blankItemTemplate() || <BlankItem />}
        </View>
    )}
    {!!this.state.items.length && (
        <List items={this.state.items} itemTemplate={itemTemplate} />
    )}
</ScrollView>
但每当我的“PullToRefresh”在这里时,我就会遇到这个错误

refreshControl={
    (pullToRefresh == 'conversations') &&
    <RefreshControl
        refreshing={this.state.refreshing}
        onRefresh={this._onRefresh.bind(this)}
    />
}
刷新控件={
(pullToRefresh==“对话”)&&
}
请参阅此链接以供参考


代码的问题就在这里

refreshControl={
    (pullToRefresh == 'conversations') &&
    <RefreshControl
        refreshing={this.state.refreshing}
        onRefresh={this._onRefresh.bind(this)}
    />
}
刷新控件={
(pullToRefresh==“对话”)&&
}
如果pullToRefresh值为“”refreshControl的值为false,因为它没有默认值,所以语句的计算结果为false,而ScrollView需要一个React元素,而不是布尔值,所以您需要更改代码,以便refeshControl应该有一个默认值,可以在将render函数的值返回如下

const refreshControl = <span>here your default value</span>;
if (pullToRefresh === 'conversations') {
    refreshControl = (
        <RefreshControl
            refreshing={this.state.refreshing}
            onRefresh={this._onRefresh.bind(this)}
        />
    );
}
const refreshControl=这里是您的默认值;
如果(pullToRefresh==='conversations'){
刷新控制=(
);
}

现在refreshControl有了一个默认值,您应该基于ScrollView组件以我的示例为参考来修改代码

refreshControl={
    (pullToRefresh == 'conversations') &&
    <RefreshControl
        refreshing={this.state.refreshing}
        onRefresh={this._onRefresh.bind(this)}
    />
}
刷新控件={
(pullToRefresh==“对话”)&&
}
如果pullToRefresh值为“”refreshControl的值为false,因为它没有默认值,所以语句的计算结果为false,而ScrollView需要一个React元素,而不是布尔值,所以您需要更改代码,以便refeshControl应该有一个默认值,可以在将render函数的值返回如下

const refreshControl = <span>here your default value</span>;
if (pullToRefresh === 'conversations') {
    refreshControl = (
        <RefreshControl
            refreshing={this.state.refreshing}
            onRefresh={this._onRefresh.bind(this)}
        />
    );
}
const refreshControl=这里是您的默认值;
如果(pullToRefresh==='conversations'){
刷新控制=(
);
}

现在refreshControl有一个默认值,您应该基于ScrollView组件以我的示例为参考,使用&&passes false(如果pullToRefresh!=)修改代码对话的反应不能呈现。如果没有要渲染的内容,则传递null

   (pullToRefresh == 'conversations') ?
         <RefreshControl refreshing={this.state.refreshing} onRefresh=this._onRefresh.bind(this)} />:null
(pullToRefresh=='conversations')?
:null

如果pullToRefresh!='对话的反应不能呈现。如果没有要渲染的内容,则传递null

   (pullToRefresh == 'conversations') ?
         <RefreshControl refreshing={this.state.refreshing} onRefresh=this._onRefresh.bind(this)} />:null
(pullToRefresh=='conversations')?
:null

您的
此.state.刷新类型是什么?它是布尔值。true/false ScrollViewconst{searchTemplate,itemTemplate,blankItemTemplate,shouldScrollToEnd,pullToRefresh}=this.props中refreshControl的属性类型是什么;使用三元运算符(pullToRefresh=='conversations')?:null您的
此.state.refreshing
类型是什么?它是布尔值。true/false ScrollViewconst{searchTemplate,itemTemplate,blankItemTemplate,shouldScrollToEnd,pullToRefresh}=this.props中refreshControl的属性类型是什么;使用三元运算符(pullToRefresh=='conversations')?:Null如何在组件内部传递此IF?定义变量并在渲染函数的返回值之前使用IF语句,然后将变量本身传递给组件,如const refreshControl=此处为默认值;if(pullToRefresh==='conversations'){refreshControl=();}return你能把它写下来作为答案吗?我如何在组件内部传递这个IF?定义变量并在render函数的返回值之前使用IF语句,然后将变量本身传递给组件,如const refreshControl=此处为默认值;如果(pullToRefresh==='conversations'){refreshControl=();}返回,你能写下来作为回答吗?