{"id":3318,"date":"2014-12-12T00:34:46","date_gmt":"2014-12-11T16:34:46","guid":{"rendered":"https:\/\/sdeno.com\/?p=3318"},"modified":"2014-12-12T00:35:27","modified_gmt":"2014-12-11T16:35:27","slug":"angularjs-filter-%e8%bf%87%e6%bb%a4%e5%99%a8%e4%be%8b%e5%ad%90","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=3318","title":{"rendered":"angularjs filter \u8fc7\u6ee4\u5668\u4f8b\u5b50"},"content":{"rendered":"<p><span style=\"color: #ff0000;\">1\uff0cuppercase\uff0clowercase\u5927\u5c0f\u8f6c\u6362<\/span><\/p>\n<p>{{ &#8220;lower cap string&#8221; | uppercase }} \/\/\u7ed3\u679c\uff1aLOWER CAP STRING<br \/>\n{{ &#8220;TANK is GOOD&#8221; | lowercase }} \/\/\u7ed3\u679c\uff1atank is good<br \/>\n<span style=\"color: #ff0000;\">2\uff0cjson\u683c\u5f0f\u5316<\/span><\/p>\n<p>{{ {foo: &#8220;bar&#8221;, baz: 23} | json }} \/\/\u7ed3\u679c\uff1a{ &#8220;foo&#8221;: &#8220;bar&#8221;, &#8220;baz&#8221;: 23 }<\/p>\n<p>\uff08\u6ce8\u610f\uff1abza\u6ca1\u683c\u5f0f\u524d\u662f\u6ca1\u6709\u53cc\u5f15\u53f7\u7684\uff0c\u683c\u5f0f\u5316\u540e\u5c31\u8f6c\u6362\u6210\u4e86json\u6570\u636e\u4e86\u3002\uff09<br \/>\n<span style=\"color: #ff0000;\">3\uff0cdate\u683c\u5f0f\u5316<\/span><\/p>\n<a href=\"https:\/\/sdeno.com\/wp-content\/uploads\/2014\/12\/date1.jpg\"><figure class=\"mdx-lazyload-container\" style=\"max-width:640px\"><div style=\"padding-top:133.75%\"><\/div><div class=\"mdx-img-loading-sp mdui-valign\"><div><div class=\"mdui-spinner\"><\/div><\/div><\/div><img width=\"640\" height=\"856\" class=\"alignnone size-full wp-image-3319 lazyload\" title=\"date1\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"https:\/\/sdeno.com\/wp-content\/uploads\/2014\/12\/date1.jpg\" alt=\"date1\" data-srcset=\"https:\/\/sdeno.com\/wp-content\/uploads\/2014\/12\/date1.jpg 640w, https:\/\/sdeno.com\/wp-content\/uploads\/2014\/12\/date1-224x300.jpg 224w, https:\/\/sdeno.com\/wp-content\/uploads\/2014\/12\/date1-624x834.jpg 624w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\"><\/figure><\/a>\n<p><a href=\"https:\/\/sdeno.com\/wp-content\/uploads\/2014\/12\/date2.jpg\"><figure class=\"mdx-lazyload-container\" style=\"max-width:640px\"><div style=\"padding-top:133.75%\"><\/div><div class=\"mdx-img-loading-sp mdui-valign\"><div><div class=\"mdui-spinner\"><\/div><\/div><\/div><img width=\"640\" height=\"856\" class=\"alignnone size-full wp-image-3320 lazyload\" title=\"date2\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"https:\/\/sdeno.com\/wp-content\/uploads\/2014\/12\/date2.jpg\" alt=\"date2\" data-srcset=\"https:\/\/sdeno.com\/wp-content\/uploads\/2014\/12\/date2.jpg 640w, https:\/\/sdeno.com\/wp-content\/uploads\/2014\/12\/date2-224x300.jpg 224w, https:\/\/sdeno.com\/wp-content\/uploads\/2014\/12\/date2-624x834.jpg 624w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\"><\/figure><\/a><br \/>\n<span style=\"color: #ff0000;\">4\uff0cnumber\u683c\u5f0f\u5316<\/span><\/p>\n<p>{{ 1.234567 | number:1 }} \/\/\u7ed3\u679c\uff1a1.2<br \/>\n{{ 1234567 | number }} \/\/\u7ed3\u679c\uff1a1,234,567<br \/>\n<span style=\"color: #ff0000;\">5\uff0ccurrency\u8d27\u5e01\u683c\u5f0f\u5316<\/span><\/p>\n<p>{{ 250 | currency }} \/\/\u7ed3\u679c\uff1a$250.00<br \/>\n{{ 250 | currency:&#8221;RMB \uffe5 &#8221; }} \/\/\u7ed3\u679c\uff1aRMB \uffe5 250.00<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">6\uff0cfilter\u67e5\u627e<\/span><br \/>\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u53ef\u4ee5\u662f\uff1a\u5b57\u7b26\u4e32\uff0c\u5bf9\u8c61\uff0c\u51fd\u6570<\/p>\n<p>{{ [{&#8220;age&#8221;: 20,&#8221;id&#8221;: 10,&#8221;name&#8221;: &#8220;iphone&#8221;},<br \/>\n{&#8220;age&#8221;: 12,&#8221;id&#8221;: 11,&#8221;name&#8221;: &#8220;sunm xing&#8221;},<br \/>\n{&#8220;age&#8221;: 44,&#8221;id&#8221;: 12,&#8221;name&#8221;: &#8220;test abc&#8221;}<br \/>\n] | filter:&#8217;s&#8217;}} \/\/\u67e5\u627e\u542b\u6709\u6709s\u7684\u884c<\/p>\n<p>\/\/\u4e0a\u4f8b\u7ed3\u679c\uff1a[{&#8220;age&#8221;:12,&#8221;id&#8221;:11,&#8221;name&#8221;:&#8221;sunm xing&#8221;},{&#8220;age&#8221;:44,&#8221;id&#8221;:12,&#8221;name&#8221;:&#8221;test abc&#8221;}]<\/p>\n<p>{{ [{&#8220;age&#8221;: 20,&#8221;id&#8221;: 10,&#8221;name&#8221;: &#8220;iphone&#8221;},<br \/>\n{&#8220;age&#8221;: 12,&#8221;id&#8221;: 11,&#8221;name&#8221;: &#8220;sunm xing&#8221;},<br \/>\n{&#8220;age&#8221;: 44,&#8221;id&#8221;: 12,&#8221;name&#8221;: &#8220;test abc&#8221;}<br \/>\n] | filter:{&#8216;name&#8217;:&#8217;iphone&#8217;} }} \/\/\u67e5\u627ename\u4e3aiphone\u7684\u884c<\/p>\n<p>\/\/\u4e0a\u4f8b\u7ed3\u679c:[{&#8220;age&#8221;:20,&#8221;id&#8221;:10,&#8221;name&#8221;:&#8221;iphone&#8221;}]<\/p>\n<p>&nbsp;<\/p>\n<p>{{ [&#8216;Ari&#8217;,&#8217;likes&#8217;,&#8217;to&#8217;] | filter:run }}<\/p>\n<p>\/\/\u4e0a\u4f8b\u7ed3\u679c: [&#8220;Ari&#8221;]<\/p>\n<p>$scope.run=function(str){<br \/>\nreturn str[0]==str[0].toUpperCase();<br \/>\n}<br \/>\n<span style=\"color: #ff0000;\">7\uff0climitTo\u5b57\u7b26\u4e32\uff0c\u5bf9\u50cf\u7684\u622a\u53d6<\/span><br \/>\n{{ &#8220;i love tank&#8221; | limitTo:6 }} \/\/\u7ed3\u679c\uff1ai love<br \/>\n{{ &#8220;i love tank&#8221; | limitTo:-4 }} \/\/\u7ed3\u679c\uff1atank<\/p>\n<p>{{ [{&#8220;age&#8221;: 20,&#8221;id&#8221;: 10,&#8221;name&#8221;: &#8220;iphone&#8221;},<br \/>\n{&#8220;age&#8221;: 12,&#8221;id&#8221;: 11,&#8221;name&#8221;: &#8220;sunm xing&#8221;},<br \/>\n{&#8220;age&#8221;: 44,&#8221;id&#8221;: 12,&#8221;name&#8221;: &#8220;test abc&#8221;}<br \/>\n] | limitTo:1 }} \/\/\u7ed3\u679c\uff1a[{&#8220;age&#8221;:20,&#8221;id&#8221;:10,&#8221;name&#8221;:&#8221;iphone&#8221;}]<br \/>\n<span style=\"color: #ff0000;\">8\uff0corderBy\u5bf9\u50cf\u6392\u5e8f<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>{{ [{&#8220;age&#8221;: 20,&#8221;id&#8221;: 10,&#8221;name&#8221;: &#8220;iphone&#8221;},<br \/>\n{&#8220;age&#8221;: 12,&#8221;id&#8221;: 11,&#8221;name&#8221;: &#8220;sunm xing&#8221;},<br \/>\n{&#8220;age&#8221;: 44,&#8221;id&#8221;: 12,&#8221;name&#8221;: &#8220;test abc&#8221;}<br \/>\n] | orderBy:&#8217;id&#8217;:true }} \/\/\u6839id\u964d\u5e8f\u6392<\/p>\n<p>{{ [{&#8220;age&#8221;: 20,&#8221;id&#8221;: 10,&#8221;name&#8221;: &#8220;iphone&#8221;},<br \/>\n{&#8220;age&#8221;: 12,&#8221;id&#8221;: 11,&#8221;name&#8221;: &#8220;sunm xing&#8221;},<br \/>\n{&#8220;age&#8221;: 44,&#8221;id&#8221;: 12,&#8221;name&#8221;: &#8220;test abc&#8221;}<br \/>\n] | orderBy:&#8217;id&#8217; }} \/\/\u6839\u636eid\u5347\u5e8f\u6392<br \/>\n<span style=\"color: #ff0000;\">9,\u81ea\u5b9a\u4e49\u8fc7\u6ee4\u5668filter<\/span><br \/>\n\u5c06\u5b57\u7b26\u4e32\u7684\u9996\u5b57\u6bcd\u6362\u6210\u5927\u5199<br \/>\nangular.module(&#8216;myapp&#8217;,[]).filter(&#8216;myfilter&#8217;,function(){<br \/>\nreturn function(str){<br \/>\nif(str){<br \/>\nreturn input[0].toUpperCase()+str.slice(1);<br \/>\n}<br \/>\n}<br \/>\n})<br \/>\n{{&#8216;my name is chenge&#8217; | lowercase | myfilter}}<\/p>\n<p>\/\/\u7ed3\u679c\uff1aMy name is chenge<\/p>\n<p>http:\/\/blog.51yip.com\/jsjquery\/1592.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\uff0cuppercase\uff0clowercase\u5927\u5c0f\u8f6c\u6362 {{ &#8220;lower cap string&#038;#8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-3318","post","type-post","status-publish","format-standard","hentry","category-angularjs"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/3318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3318"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/3318\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}