亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

NGRX 實體 updateOne 不工作:id undefined

NGRX 實體 updateOne 不工作:id undefined

素胚勾勒不出你 2023-03-10 13:59:26
我決定尋求幫助,我就是無法理解 NGRX 實體!(此代碼最初由 NX 創建)。我遵循了 NGRX Entity 指南,我也看了很多教程視頻,但我仍然無法讓NGRX Entity updateOne工作。在下面收到此錯誤 - 我可以毫無問題地將實體加載到商店中,并且這些可以很好地構建我的 UI。我有一個實體按鈕集合,并希望在單擊時更新按鈕的存儲狀態 - 僅此而已?。ㄈ魏蜗敕槭裁催@不起作用??)ERROR TypeError: Cannot read property 'id' of undefined    at http://localhost:4200/vendor.js:83815:26    at Array.filter (<anonymous>)    at updateManyMutably (http://localhost:4200/vendor.js:83811:27)    at updateOneMutably (http://localhost:4200/vendor.js:83801:16)    at Object.operation [as updateOne] (http://localhost:4200/vendor.js:83622:27)    at http://localhost:4200/main.js:1169:28    at http://localhost:4200/vendor.js:88532:26    at reducer (http://localhost:4200/main.js:1173:12)    at http://localhost:4200/vendor.js:87072:20    at combination (http://localhost:4200/vendor.js:86960:37) 這是我到目前為止的代碼:// stateexport interface QuickButton {    id: number;    isSelected: boolean;    title: string;    linkUrl: string;}// in componentthis.store.dispatch( actions.setQuickFilter( evt ) );// evt = {id: 1, isSelected: true, linkUrl: "", title: "Video"}// in actionsexport const setQuickFilter = createAction(  '[QuickBar] setQuickFilter',  props<{update: Update<QuickButton>}>());// in reducerexport const QUICKBAR_FEATURE_KEY = 'quickBar';export interface State extends EntityState<QuickButton> {  selectedId?: string | number; // which QuickBar record selected  loaded: boolean; // has the QuickBar list been loaded  error?: string | null; // last none error (if any)}export interface QuickBarPartialState {  readonly [QUICKBAR_FEATURE_KEY]: State;}export const quickBarAdapter: EntityAdapter<QuickButton> = createEntityAdapter<QuickButton>();export const initialState = quickBarAdapter.getInitialState({  // set initial required properties  loaded: false,});const quickBarReducer = createReducer(  initialState,
查看完整描述

2 回答

?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

您錯誤地調度了您的操作。

this.store.dispatch(actions.setQuickFilter(evt));

應該

this.store.dispatch(actions.setQuickFilter({ update: evt }));


查看完整回答
反對 回復 2023-03-10
?
慕森王

TA貢獻1777條經驗 獲得超3個贊

耶?。∽詈?。這是一個真正的愚蠢錯誤——因為不理解實體。大量的反復試驗和記錄來解決這個問題!

解決方案:更改組件中的調度調用:

this.store.dispatch( actions.setQuickFilter( {update: evt} } ) );

到:

this.store.dispatch( actions.setQuickFilter( {update: {id: evt.id, changes: evt} } ) );

現在,我所有訂閱的功能都可以使用按鈕中的更新值來控制它們自己的 UI 元素。最后!


查看完整回答
反對 回復 2023-03-10
  • 2 回答
  • 0 關注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號