2013-06-04 11 views

उत्तर

31

अद्यतन:filterProperty() को filterBy() द्वारा प्रतिस्थापित किया गया है। उपयोग एक ही है, नीचे टिप्पणी देखें।

filterBy()filter() के लिए शॉर्टकट है जो आपको संख्यात्मक तत्वों की निर्दिष्ट संपत्ति के आधार पर त्वरित रूप से फ़िल्टर करने देता है। filter() का प्रयोग करें अगर आप कुछ और अधिक जटिल या बाहर के-साधारण जहां filterBy() उपयोग नहीं कर सकते करने की ज़रूरत है।

उदाहरण के लिए, आप यह सोचते हैं इस तरह की वस्तुओं की एक सरणी था:

[ 
    {firstName: 'Kris', lastName: 'Selden'}, 
    {firstName: 'Luke', lastName: 'Melia'}, 
    {firstName: 'Formerly Alex', lastName: 'Matchneer'} 
] 

और तुम एक गणना संपत्ति सरणी फिल्टर करने के लिए केवल firstName == 'Luke' के साथ लोगों में शामिल हैं का उपयोग करता है करना चाहते थे:

filter() का उपयोग कर:

filterComputed: function() { 
    return this.get('content').filter(function(item, index, enumerable){ 
    return item.firstName == 'Luke'; 
    }); 
}.property('[email protected]') 

0 का उपयोग कर:

filterByComputed: function() { 
    return this.get('content').filterBy('firstName', 'Luke'); 
}.property('[email protected]') 

JSBin example

+11

नायब '' filterProperty' filterBy' के पक्ष में पदावनत किया गया है। एक ही उपयोग। https://github.com/emberjs/website/pull/882 – andorov

संबंधित मुद्दे