【发布时间】:2020-04-16 14:59:44
【问题描述】:
我想使用react-resolver 模块来使用我的数据模拟,但我不确定我做错了什么。
目前我有以下情况正常工作
我有我的数据对象:
const data = [
{
team: "TeamA",
position: "dx",
active: "No",
},
{
team: "TeamB",
position: "dx",
active: "Yes",
},
{
team: "TeamC",
position: "sx",
active: "No",
},
{
team: "TeamD",
position: "dx",
active: "No",
},
{
team: "TeamE",
position: "dx",
active: "No",
}
]
我可以映射它并将这个数据对象呈现在我的表格组件的行中,例如rows={renderRows(data)}
现在我想使用react-resolver,我已经创建了一个 Mock 文件夹,我已经放置了我的数据对象。
这就是现在的样子
import { resolver } from "../../path/of/my/resolver";
export const newDataResolver = resolver({
const data = [
{
team: "TeamA",
position: "dx",
active: "No",
},
{
team: "TeamB",
position: "dx",
active: "Yes",
},
{
team: "TeamC",
position: "sx",
active: "No",
},
{
team: "TeamD",
position: "dx",
active: "No",
},
{
team: "TeamE",
position: "dx",
active: "No",
}
]
});
我现在像这样在我的组件中导入它
import { newDataResolver } from "../Mock"
我现在如何在我的renderRows 中使用我的newDataResolver 对象,它是从模型导入的?
这是一个非常基本的问题,但我很挣扎。我现在想做类似rows={renderRows(newDataResolver)}
【问题讨论】:
标签: javascript reactjs mocking resolver