相关疑难解决方法(0)

从JavaScript中的对象数组中删除重复项

我有一个包含对象数组的对象.

things = new Object();

things.thing = new Array();

things.thing.push({place:"here",name:"stuff"});
things.thing.push({place:"there",name:"morestuff"});
things.thing.push({place:"there",name:"morestuff"});
Run Code Online (Sandbox Code Playgroud)

我想知道从数组中删除重复对象的最佳方法是什么.所以,例如,事情会变成......

{place:"here",name:"stuff"},
{place:"there",name:"morestuff"}
Run Code Online (Sandbox Code Playgroud)

javascript arrays object duplicates

306
推荐指数
29
解决办法
32万
查看次数

BehaviourSubject的distinctUntilChanged()不是函数

我是Rxjs的新手我正在尝试理解下面的BehaviourSubject是我的代码

export interface State {
    items: Items[]
}

const defaultState = {
    items: []
};

const _store = new BehaviorSubject<State>(defaultState);

@Injectable()
export class Store {
    private _store = _store;
    changes = this._store.distinctUntilChanged()
        .do(() => console.log('changes'));

    setState(state: State) {
        this._store.next(state);
    }

    getState() : State {
        return this._store.value;
    }

    purge() {
        this._store.next(defaultState);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行我的项目时,我在我的控制台中收到此错误

platform-browser.umd.js:1900 EXCEPTION: Error: Uncaught (in promise):
EXCEPTION: Error during instantiation of Store! (StoreHelper -> Store).
ORIGINAL EXCEPTION: TypeError: this._store.distinctUntilChanged is not a function
Run Code Online (Sandbox Code Playgroud)

谁能帮我吗.此外,如果我想要做的是为我的模型对象创建一个商店,所以如果有任何其他更简单的方式随时建议它.

任何帮助表示赞赏.

rxjs typescript angular

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

arrays ×1

duplicates ×1

javascript ×1

object ×1

rxjs ×1

typescript ×1