我正在将一些JSON文件导入:
import general from './Data/general.json';
import health from './Data/health.json';
import business from './Data/business.json';
我正在尝试通过JSON文件中的数组“文章”迭代,文件的名称与我通过的类别prop相同。因此,我想知道如何使用Prop Inputs更改映射功能从中获取数据的文件,这些文件输入会在Navbar上按下按钮的按下。
尝试此操作,但它不起作用:
{props.category.articles.map((element)=> {
执行此操作,但我无法根据道具进行更改:
{general.articles.map((element)=> {
我尝试过将props.category in {},()封闭,并在将它们声明为const变量后传递,但似乎没有一个工作。
I'm importing some json files as :
import general from './Data/general.json';
import health from './Data/health.json';
import business from './Data/business.json';
And I am trying to iterate through an array "articles" in the json file, the names of the files are same as the category prop I'm passing. So, I want to know how can I change the file from which my map function takes data using prop inputs which change on press of buttons on the navbar.
Trying this, but it doesn't work:
{props.category.articles.map((element) => {
Doing this works but I can't change it according to the prop:
{general.articles.map((element) => {
I've tried enclosing props.category in { },( ), and passing them after declaring them in a const variable but none of it seems to work.
发布评论
评论(1)
你可以尝试这样的东西
You can try something like this