javascript - Angular object array to column array -


मेरे पास वस्तु है, जिसमें फ़ील्ड id और text और संभवत: अधिक अन्य फ़ील्ड।

अरै में बहुत सारे ऑब्जेक्ट हैं, और मैं उसे एक टेक्स्ट एरे में परिवर्तित करना चाहता हूं।

यह इस समय मेरे पास है। किसी भी सुंदर समाधान, संभव कुछ LINQ की तरह?

  var ईमेल = नए सरणी (); Angular.forEach (this.form.Emails, फ़ंक्शन (ईमेल) {emails.push (email.text);});    

<पी> @ निक्स की तरह आपने उत्तर दिया, आप का उपयोग कर सकते हैं अंडरस्कोर लाइब्रेरी।

संपत्ति मूल्यों की एक सूची को निकालने


उदाहरण:

 < कोड> this.form.Emails = [{text: 'moe', id: 1}, {text: 'larry', id: 2}, {text: 'curly', id: 3}]; Var ईमेल = _.प्लक (this.form.Emails, 'text'); // ouput ["मो", "लारी", "घुंघराले"]   

वैसे भी मैं आपको अपना कोड संस्करण छोड़ने का सुझाव देता हूं (उर्फ angular.forEach )। क्योंकि अन्य प्रोग्रामर जो आपके कोड को बनाए रखता है, उन्हें पता होना चाहिए कि pluck क्या करता है

अपना कोड सरल बनाओ

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -