Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/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 如何在react native中使用sectionList显示数据?_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 如何在react native中使用sectionList显示数据?

Javascript 如何在react native中使用sectionList显示数据?,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我想在react native中使用节列表显示数据。我正在使用reduce()提取数据,但我无法理解为什么会出现未定义的行为,比如请为react native render html提供html或uri作为道具 我想将sectionList项目显示为HTML内容,sectionList的标题是规范数据中的标题 const specificationsData = specifications.reduce( (acc, curValue) => { if (cur

我想在react native中使用节列表显示数据。我正在使用
reduce()
提取数据,但我无法理解为什么会出现未定义的行为,比如请为
react native render html
提供html或uri作为道具

我想将sectionList项目显示为HTML内容,sectionList的标题是
规范数据中的标题

const specificationsData = specifications.reduce( (acc, curValue) => {

            if (curValue.title !== undefined && curValue.description !== undefined){

                let newObj = {};

                newObj['data'] = curValue.description;

                newObj['title'] = curValue.title;

                console.log(curValue.title)

                acc.push(newObj);

                return acc;
            }

        }, []);

        console.log(specificationsData)
上述日志的结果:

现在,我将上述数据传递到
部分列表中

import HTMLView from 'react-native-render-html';

<SectionList
                    renderItem={({item, index, section}) => <HTMLView key={index} value={item}/>}
                    renderSectionHeader={({section: {title}}) => (
                        <Text style={{fontWeight: 'bold', color: 'red'}}>{title}</Text>
                    )}
                    sections={specificationsData}
                    keyExtractor={(item, index) => item + index}
                />
从'react native render html'导入HTMLView;
}
renderSectionHeader={({section:{title}}})=>(
{title}
)}
节={specificationsData}
keyExtractor={(项,索引)=>item+index}
/>
如何通过传递
规范数据来传递
部分列表的显示数据和标题

请参见上述代码的屏幕截图:

根据,数据需要是
规范数据中的一个数组。更新以下行:

newObj['data'] = [curValue.description];
发布来自的结果,因为我认为您的问题最有可能与
({section:{title}})有关
@FrankerZ请参见屏幕截图->此代码->
{title}
非常完美,我认为
HTMLView存在一些问题