gpt4 book ai didi

angular - 传递给 `selectId` 实现的实体返回未定义。您可能应该提供自己的 `selectId` 实现

转载 作者:行者123 更新时间:2023-12-04 09:58:41 24 4
gpt4 key购买 nike

The Warning is here

enter image description here

https://github.com/rokudo5262/phone这是我的项目
我想在智能表中加载品牌列表但收到警告
我尝试修复但警告仍然存在请帮助
Brands-features.selector.ts

import { createFeatureSelector } from '@ngrx/store';
import { State, FeatureKey } from '../reducers';

export const selectBrandsState = createFeatureSelector<State>(FeatureKey);

Brands.selector.ts

import { createSelector } from '@ngrx/store';
import { selectBrandsState } from './brands-features.selector';
import { BrandsReducer } from '../reducers';
import { brandAdapter } from '../states/brands.state';

export const selectBrandEntitiesState = createSelector(
selectBrandsState,
state => state[BrandsReducer.brandsFeatureKey],
);

export const {
selectIds: selectBrandIds,
selectEntities: selectBrandEntities,
selectAll: selectAllBrands,
selectTotal: selectTotalBrands,
} = brandAdapter.getSelectors(selectBrandEntitiesState);

export const BrandSelectors = {
selectBrandEntitiesState,
selectBrandIds,
selectBrandEntities,
selectAllBrands,
selectTotalBrands,
};
export const selectCurrentBrand = (brand_id) => createSelector(
selectBrandEntities,
(brand) => brand[brand_id],
)

选择器/index.ts

export * from './brands-features.selector';
import * as BrandsSelector from './brands.selector';

export {
BrandsSelector,
};

品牌.reducer.ts

import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
import { IBrand } from '../../../@core/data/brands';

export interface BrandsState extends EntityState<IBrand> {
selectedBrandID: number | string | null;
}
export const brandAdapter: EntityAdapter<IBrand> = createEntityAdapter<IBrand>({
selectId: (brand: IBrand) => brand.brand_id,
sortComparer: null,
});

export const brandInitialState: BrandsState = brandAdapter.getInitialState({
selectedBrandID: null,
entities: {
0: {},
},
});

最佳答案

我发现了问题,原来问题是我的 Brand Table 中的“brand_id”,entity.Property(e => e.BrandId).HasColumnName( "brand_id");brand_id 在我的 Ibrand interface 中,而不是在代码中。所以我将所有内容都更改为 brandCode 并且警告消失了。


modelBuilder.Entity<Brands>(entity =>
{
entity.HasKey(e => e.BrandCode)

entity.Property(e => e.BrandCode).HasColumnName("brandCode");

entity.Property(e => e.BrandName)
.HasColumnName("brandName")
.HasMaxLength(255);

entity.Property(e => e.CreatedBy)
.HasColumnName("createdBy")
.HasMaxLength(255);

entity.Property(e => e.CreatedDateTime)
.HasColumnName("createdDateTime")
.HasColumnType("datetime");

entity.Property(e => e.Deleted).HasColumnName("deleted");

entity.Property(e => e.Remark)
.HasColumnName("remark")
.HasMaxLength(255);

entity.Property(e => e.Status)
.HasColumnName("status")
.HasMaxLength(255);

entity.Property(e => e.UpdatedDateTime)
.HasColumnName("updatedDateTime")
.HasColumnType("datetime");

entity.Property(e => e.Updatedby)
.HasColumnName("updatedby")
.HasMaxLength(255);
});
export const brandAdapter: EntityAdapter<IBrand> = createEntityAdapter<IBrand>({
selectId: (brand: IBrand) => brand.brandCode,
sortComparer: null,
});
export interface IBrand {
brandCode: number;
brandName: string;
status: string;
remark: string;
deleted: boolean;
createdBy?: string;
createdDateTime?: Date;
lastUpdatedBy?: string;
lastUpdatedDateTime?: Date;
}

关于angular - 传递给 `selectId` 实现的实体返回未定义。您可能应该提供自己的 `selectId` 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61870380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com