- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
react 管理员的 Resource
组件映射name
prop 值到端点。
例如。从 访问数据。 http://example.com/abc
,您的 Resource
组件看起来像这样:<Resource name='abc'/>
我想在 http://example.com/abc/def
访问资源?
此 <Resource name='abc/def'/>
甚至不调用 dataProvider
功能。
我不想最终得到丑陋的解决方案,例如:
// App.js
<Resource name='def'/>
// dataProvider.js
if (resource==='def') {
url = 'abc/def'
}
/
?任何黑客?
最佳答案
我正在开发一个项目,在该项目中我们最终编写了自己的 dataProvider,因为我们的 api 并不是严格意义上的 Restful。
绕着你的脑袋有点皮塔饼,但一旦你弄清楚工作流程,它就不算太糟糕。
基本上在调用 dataProvider 时会发生三件事
// import all the things
// set your api path prefix
const convertDataProviderRequestToHTTP = (type, resource, params) => {
//switch statement with one case for each action type
// and some logic where necessary for different resources ie.
switch(type){
case "GET_ONE":{
// if statements to handle resources with goofy endpoints
if(resource === 'abc/def'){
const url = `${API_PREFIX}/abc/def`;
const options = {
// set the specific options that you need for a
// each particular resource
}
}
// handles resources with normal restful endpoints
const url = `${API_PREFIX}/${RESOURCE}`;
const options = {
// this part depends on how you're doing your fetching
// might need to include the particular rest verb
// and any other settings
}
}
}
return {
url,
options
}
}
const convertHTTPResponseToDataProvider = (response, type, resource, params){
// another switch statement that converts the response that you get
// from your api to something that's useful to your Resource
switch(type){
case 'GET_ONE':{
if(resource === 'abc/def'){
// convert response into something useful and return it
return{
data: convertedResponse
}
}
}
}
}
export default (type, resource, params) => {
// this comes from react-admin, you could use plain old fetch or
// your favorite fetch library like axios instead
const { fetchJson } = fetchUtils;
// part 1, using the stuff that was sent in the dataProvider
// call to generate what you need to sending your fetch
const { url, options } = convertDataProviderRequestToHTTP(
type,
resource,
params
);
// add logic for grabbing your tokens and adding headers to options here
options.headers.set('headerkey', 'headervalue');
// part 2 sending the fetch request
return fetchJson(url, options).then(response =>
// part 3, converting the response and returning it
convertHTTPResponseToDataProvider(response, type, resource, params)
);
};
关于admin-on-rest - React Admin - 如何使用像 abc/def 这样的嵌套路径调用 dataProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50414523/
这个问题已经有答案了: LIMIT is not working in ActiveDataProvider (2 个回答) 已关闭 7 年前。 偏移不起作用 - 正确吗?分页不起作用。 $query
我有一个简单的 PostControllerTest 类: client = static::createClient(); } public function idProvider(
有没有办法根据特定条件从数据提供者获取数据?类似的东西.. @Test(dataProvider = "Data-Provider-Function" class="Randomclass.class
我对没有 TestNG 的 Java 项目有以下要求,但我添加了 @Test 注释来运行该类。 1. Find the classes which are all annotated with `@c
如何使用存在于不同类中的@DataProvider? 我创建了一个不同的包,并在每个测试用例旁边定义了数据提供者。请分享我如何在不同的类里面使用它。 最佳答案 您可以使用@Test 的dataProv
我的@DataProvider看起来像这样: @DataProvider(name = "data") public Object[][] data() throws Exceptio
我有一个 Excel 电子表格,其中存储了所有测试信用卡。这些信用卡有不同的类型。其中一些是 VISA,其他是 MasterCard、Amex 等... 我有一个测试用例,其中我有时想使用 VISA
我已阅读有关该主题的文档,并且我的代码符合数据提供程序实现的所有要求。首先,here's the full code of the test以防万一。 这是实现数据提供者的功能: /** * Tes
我正在使用一个数组来填充一个 DataProvider,我正在使用它来填充一个列表组件。像这样: var myDataProvider = new DataProvider(this.myArray)
我有一个 PHPUnit 测试,它使用 @dataProvider .数据提供者检查文件系统中的某些文件。 但是,我在不同的环境中使用此测试,这意味着可能会发生文件不存在的情况。这意味着 dataPr
我想将网格中的一些数据延迟加载到我的 Vaadin View 中。网格行有时非常大,所以我想限制一次加载的行数,假设为 2。 我尝试使用 DataProvider.fromCallbacks() 来做
我如何计算 $dataProvider 检索的数据?我尝试过使用此代码, $dataProvider = new CActiveDataProvider('Model');
我有一个包含完整测试数据的 TestNG Dataprovider。我正在解析 Excel 工作表,因此 dataprovider 有例如。 15个测试数据列表。 我不想使用所有 15 个测试数据集运
这个问题已经有答案了: What causes a java.lang.StackOverflowError (13 个回答) 已关闭 4 年前。 我正在使用 Excel 工作表,因为我正在使用数据提
我需要在来自 DataProvider 的每个数据之前运行一些测试。 例如,在下面的示例类中,我需要运行 someStart 测试 4 次(在每个数据之前),如何执行此操作? public class
我有一组测试总共需要很长时间才能执行。我想通过将所有数据提供者更改为仅返回一组参数来缩短我的一些测试运行。 我已经通读了 TestNG 文档和 javadoc,但似乎没有像 IDataProvider
首先,我正在构建一个基于 Selenium 和 Java 的自动化库。我正在构建一种参数化传递到测试方法的数据的方法。我正在使用 TestNG。 现在我有两个示例测试方法,它们采用不同的数据模型作为参
您好,我正在使用 TestNG 在 Eclipse indigo 上进行测试。我已经设置了 DataProvider,奇怪的是控件正在跳过 DataProvider。它执行@BeforeClass和@
我有一个 DataProvider 可以读取如下所示的 CSV 文件 john|26|mba claire|33|bbl knight|29|mpa 现在我有三个类,每个类有一个@Test 类名是 N
我想在类中与数据提供程序并行运行测试方法。我需要一个数据提供程序,每次在新的测试方法开始为给定的测试运行生成部分动态数据之前都会调用该数据提供程序。让我用伪代码解释一下: @DataProvider(
我是一名优秀的程序员,十分优秀!