考虑到下面的简化模型,我想写一条规则MyCollection contains MyField
,但是我得到的只是数据源项列表,以供选择,就好像集合的ValueInputType仅适用于User。我应该在模型中进行哪些更改以实现该目标?
public class MyModel
{
[Field(Settable = false, DataSourceName = "MyDataSource")]
public int MyField { get; set; }
[Field(Settable = false, ValueInputType = ValueInputType.All, DataSourceName = "MyDataSource"))]
public List<int> MyCollection { get; set; }
}
答案 0 :(得分:0)
根据文档here,数字值类型的集合只能使用ValueInputType.User(在本文中间查找“ IMPORTANT!”标题之一)。因此,您不能在规则条件中使用MyField字段的值。您需要创建一个规则方法来实现该目标:
@Singleton
public class SomeService {
private final FirstRestApi firstRestApi;
private final SecondRestApi secondRestApi;
public SomeService(FirstRestApi firstRestApi, SecondRestApi secondRestApi) {
this.firstRestApi = firstRestApi;
this.secondRestApi = secondRestApi;
}
public Single<AggregatedResponse> login(String data) {
Single<FirstResponse> firstResponse = firstRestApi.call(data);
Single<SecondResponse> secondResponse = secondRestApi.call();
return firstResponse.zipWith(secondResponse, this::convertResponse);
}
private AggregatedResponse convertResponse(FirstResponse firstResponse, SecondResponse secondResponse) {
return AggregatedResponse
.builder()
.something1(firstResponse.getSomething1())
.something2(secondResponse.getSomething2())
.build();
}
}
具有这种规则的方法,您的规则应如下所示:
public bool Contains(List<int> collection, [Parameter(DataSourceName = "MyDataSource")] int i)
{
return collection.Contains(i);
}