我有一個在我的狀態容器數組,我試圖設置一個getter,將其分爲活動和不活動的容器。我使用這個來獲取下面的數組。從獲得者獲取一個選定的屬性
export const x = state => _.partition(state.containers, c => c.state === 'running');
這個問題是我想分割並分配給activeContainers和stoppedContainers,然後導出。
[
[
{
"id": "1",
"name": "test container",
"image": "some image",
"state": "running",
"status": "Running"
}
],
[
{
"id": "2",
"name": "another test container",
"image": "some image",
"state": "stopped",
"status": "Running"
}
]
]
我使用ES6的解構嘗試,但我覺得我失去了一些東西,或將解構在錯誤的地方,它與Vuex工作。
export const [activeContainers = [], stoppedContainers = []] = state => _.partition(state.containers, c => c.state === 'running');
您正試圖將一個函數分配給一個數組。這樣做不好。 – Bergi
我只想導出_.partition的結果,而不是返回2個數組,我想要一個。我知道有更簡單的方法,我只是想看看是否有可能這樣做。 –
您目前正在導出*函數*'x',而不是'state'對象或'containers'數組。那麼你如何從那裏導出兩個數組? – Bergi