2015-05-28 34 views
0

我需要將我的視圖中的$ filter過濾器移到angularjs中的控制器中。

現在,我有這樣的事情(簡化爲只希望顯示相關的東西):

//view 
    ng-repeat="thing in things | filter: 'something'" where the "something" is a property of "thing". 

//controller 
$scope.things = $filter('filter', {whatGoesHere?:something}); 

我將如何訪問相同的嵌套屬性從控制器?我對每個「東西」鍵都使用firebase是唯一的標識符。

謝謝。

編輯:我的目標是這樣的:

things: { 
    thingID1: { 
     something: 'value'; 
    }, 
    thingID2: { 
    something: 'value' 
    }, 
    ... 
} 
+0

在做了一些更多的研究之後,它看起來像我需要使用這樣的東西:https://gist.github.com/katowulf/bee266e31aa60cb0eed6但我無法fi確切地說明如何使用這個。 – EmptyPockets

回答

0

你會這樣稱呼它:

$scope.things = $filter('filter')(unfilteredThings, 'something'); 

如果你想在一個特定的屬性過濾器,你可以這樣做:

$scope.things = $filter('filter')(unfilteredThings, { thePropertyName: 'something' }); 
+0

這看起來像正確的答案,但我做錯了什麼。我在帖子中添加了一個編輯,顯示了我的對象的結構。看起來好像我無法得到嵌套的uniqueID值。 – EmptyPockets

+1

「過濾器」過濾器對數組進行操作,而您的「事物」變量不是數組,因此可能是問題所在。所以你的例子中的'something'會與'uniqueID1'匹配,並且你想獲得'{thing:'值'}'嗎?那是你想要做什麼?或者你是否正在嘗試找到'something'與'value'匹配的項目? – JLRishe

+0

我只理解它在視圖中發生了什麼,所以我會這樣描述它:「某些東西」將會是thing.something,它是對象「things」中更深層次的東西。 「事物」遍歷「事物」,它給了我uniqueID(「thing」),然後我可以訪問「something」的嵌套屬性作爲過濾器。過濾器會顯示thing.something的東西。 (抱歉,這個聲音有多混亂)編輯:另外,我更新了示例對象要更清楚。我試圖遍歷「事物」並訪問「某物」屬性。 – EmptyPockets