我正在尝试搜索数组中的元素。当获取它时,我需要在数组末尾追加一些元素。
我尝试与此类似。
List dataModelo = allMakers //THIS IS THE MAIN ARRRAY
.where((modelo) =>
modelo["fabricante"] ==
fabricante["fabricante"])
.toList()
.addAll([
{
"id": 0,
"fabricante":
'Test,
"modelo":
'Test'
}
]);
但是返回
此处的表达式的类型为“ void”,因此不能为 使用。
所以有人知道我该怎么做吗?
解决方案:
dataModelo = allMakers
.where((modelo) =>
modelo["fabricante"] ==
fabricante["fabricante"])
.followedBy([
{
"id": 0,
"fabricante":
'TEXT',
"modelo":
'TEXT'
}
]).toList();
答案 0 :(得分:1)
在final arr = [1, 2, 3];
print(arr.where((a) => a > 2).toList()
..addAll([ 4, 5 ])); // returns [3, 4, 5]
部分之后使用cascade notation。
例如
.
换句话说,在您的.addAll
部分添加另一个 @InjectMocks
private EllaService ellaService;
private IrisBo validIrisBo;
@Mock
private EllaRequestDto ellaRequestDtoMock;
@Mock
private EntityServiceConnectable<EllaResponseDto> connectorMock;
@Mock
private EllaResponseDto ellaResponseMock;
@Async
public void invokeEllaAsync( final IrisBo irisBo ) throws EllaGatewayUnsuccessfulResponseException {
try {
callEllaService( irisBo );
}
/**
* Asynchronously call Ella. Determine if traffic is applicable for Ella and if yes forward to Ella.
*
* @param irisEo
* @return List<ResultBo>
* @throws EllaGatewayUnsuccessfulResponseException
*/
catch( EllaGatewayUnsuccessfulResponseException ex ) {
throw new EllaGatewayUnsuccessfulResponseException( ex.getMessage(), ex.getCause() );
}
}
private void callEllaService( final IrisBo irisBo ) throws EllaGatewayUnsuccessfulResponseException {
HttpHeaders elladHeaders = createRequestHeaders( irisBo );
ServiceResponse<EllaResponseDto> response = connector.call( EllaDtoConverter.convertToRequest( irisBo ), elladHeaders );
if( !response.isSuccess() ) {
throw new EllaGatewayUnsuccessfulResponseException( response.getErrorMessage(), response.getException().getCause() );
}
}
应该可以解决问题。