我试图基于一些嵌套对象过滤数组.我准备了一些小提琴
输入数组如下所示:
let arrayOfElements =
[
{
"name": "a",
"subElements":
[
{"surname": 1},
{"surname": 2}
]
},
{
"name": "b",
"subElements":
[
{"surname": 3},
{"surname": 1}
]
},
{
"name": "c",
"subElements":
[
{"surname": 2},
{"surname": 5}
]
}
];
Run Code Online (Sandbox Code Playgroud)
我希望这种情况的输出看起来像这样:
let filteredArray =
[
{
"name": "a",
"subElements":
[
{"surname": 1}
]
},
{
"name": "b",
"subElements":
[
{"surname": 1}
]
}
];
Run Code Online (Sandbox Code Playgroud)
我正在使用这个公式来做到这一点:
let filteredArray = arrayOfElements.filter((element) => element.subElements.some((subElement) => subElement.surname === 1));
Run Code Online (Sandbox Code Playgroud)
输出几乎是好的,但它返回带有姓氏的所有对象的对象(更好地检查小提琴:D),而不是将它们切掉.我该如何改进过滤?
我想测试一下效果如下:
Effect 的代码如下所示:
@Effect()
continuePollingEntries$ = this.actions$.pipe(
ofType(SubnetBrowserApiActions.SubnetBrowserApiActionTypes.LoadEntriesSucces),
delay(5000),
switchMap(() => {
return this.subnetBrowserService.getSubnetEntries().pipe(
map((entries) => {
return new SubnetBrowserApiActions.LoadEntriesSucces({ entries });
}),
catchError((error) => {
return of(new SubnetBrowserApiActions.LoadEntriesFailure({ error }));
}),
);
}),
);
Run Code Online (Sandbox Code Playgroud)
我想测试的是5秒后是否发出效果:
it('should dispatch action after 5 seconds', () => {
const entries: SubnetEntry[] = [{
type: 'type',
userText: 'userText',
ipAddress: '0.0.0.0'
}];
const action = new SubnetBrowserApiActions.LoadEntriesSucces({entries});
const completion = new SubnetBrowserApiActions.LoadEntriesSucces({entries});
actions$ = hot('-a', { …Run Code Online (Sandbox Code Playgroud) 我正在做简单的WinForms应用程序,我面临一些奇怪的问题.
我的表格:
它很简单:3个组合框和两个按钮 - 确定和取消.
视图:
private void applyOrderButton_Click(object sender, EventArgs e)
{
List<string> testList = new List<string>()
{
"A",
"B",
"C"
};
comboBox1st.DataSource = testList;
comboBox2nd.DataSource = testList;
comboBox3rd.DataSource = testList;
comboBox1st.SelectedIndex = 2;
comboBox2nd.SelectedIndex = 1;
comboBox3rd.SelectedIndex = 0;
//Presenter.DoTest();
}
Run Code Online (Sandbox Code Playgroud)
在校准方法之后会发生什么applyOrderButton_Click()(单击Ok按钮后会发生)我的所有组合框都会更改所选位置.但是,每个组合框都具有相同的选定索引 - 在这种特殊情况下,它将是"A".
然后我使用我的cursour更改了更改comboBox selectedIndex(例如我选择第三个comboBox来显示"C"),对所有三个组合框执行更改.我做错了什么?
我想知道我要做的是好事还是坏事.我有那个班:
public class Element : IElement
{
public float? Max { get; private set; }
public float? Min { get; private set; }
public float? Average { get; private set; }
public bool HasValue { get; private set; }
public void SetRange(float? min, float? max)
{
if (min >= max)
{
throw new WrongElementValueException("Min must be greater than max!");
}
else if (min < 0f || max < 0f)
{
throw new WrongElementValueException("Min/max must be greater than 0!");
}
else …Run Code Online (Sandbox Code Playgroud) 当其中一个减速器需要道具时,如何组合减速器?
我有以下型号:
interface Device {
id: string;
data: IDeviceData;
}
Run Code Online (Sandbox Code Playgroud)
和 DeviceReducer 如下所示:
import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
import { Device } from '../model/device';
import { SubnetBrowserApiActions } from 'src/app/explorer/actions';
export interface State extends EntityState<Device> { }
export const adapter: EntityAdapter<Device> = createEntityAdapter<Device>();
export const initialState: State = adapter.getInitialState();
export function reducer(
state = initialState,
action:
| SubnetBrowserApiActions.SubnetBrowserApiActionsUnion
): State {
switch (action.type) {
case SubnetBrowserApiActions.SubnetBrowserApiActionTypes.LoadEntriesSucces: {
return adapter.upsertMany(action.payload.entries, state);
}
default: {
return state;
}
} …Run Code Online (Sandbox Code Playgroud) c# ×2
ngrx ×2
.net ×1
combobox ×1
exception ×1
filtering ×1
javascript ×1
ngrx-effects ×1
ngrx-store ×1
rxjs ×1
rxjs-marbles ×1
winforms ×1