传递给“selectId”实现的实体返回未定义。您可能应该提供自己的 `selectId` 实现
The entity passed to the `selectId` implementation returned undefined. You should probably provide your own `selectId` implementation
https://github.com/rokudo5262/phone 这是我的项目
我想在 smart table 中加载品牌列表,但收到警告
我尝试修复但警告仍然存在请帮忙
品牌-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],
)
selector/index.ts
export * from './brands-features.selector';
import * as BrandsSelector from './brands.selector';
export {
BrandsSelector,
};
Brand.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: {},
},
});
我想问题出在selectCurrentBrand
,你能分享一下你是如何使用它的吗?
export const selectCurrentBrand = (brand_id) => createSelector(
selectBrandEntities,
(brand) => brand[brand_id],
)
如果你像this.store.select(selectCurrentBrand, 123)
那样做,那么正确的做法是
export const selectCurrentBrand = createSelector(
selectBrandEntities,
(brand, brand_id) => brand[brand_id],
)
选择器
this.roomgroup$ = this.store.pipe(select(RoomGroupSelectors.selectCurrentRoomGroup, this.id$))
我发现了问题,原来问题是我的 Brand Table
、entity.Property(e => e.BrandId).HasColumnName("brand_id");
和 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;
}
https://github.com/rokudo5262/phone 这是我的项目
我想在 smart table 中加载品牌列表,但收到警告
我尝试修复但警告仍然存在请帮忙
品牌-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],
)
selector/index.ts
export * from './brands-features.selector';
import * as BrandsSelector from './brands.selector';
export {
BrandsSelector,
};
Brand.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: {},
},
});
我想问题出在selectCurrentBrand
,你能分享一下你是如何使用它的吗?
export const selectCurrentBrand = (brand_id) => createSelector(
selectBrandEntities,
(brand) => brand[brand_id],
)
如果你像this.store.select(selectCurrentBrand, 123)
那样做,那么正确的做法是
export const selectCurrentBrand = createSelector(
selectBrandEntities,
(brand, brand_id) => brand[brand_id],
)
选择器
this.roomgroup$ = this.store.pipe(select(RoomGroupSelectors.selectCurrentRoomGroup, this.id$))
我发现了问题,原来问题是我的 Brand Table
、entity.Property(e => e.BrandId).HasColumnName("brand_id");
和 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;
}