逗号分隔&LT; P&GT;角 [英] Comma Separated <p> angular
问题描述
我有一个pretty基本情况(有些新的角度)。我试图转换JSON:
[
{'名':'尼克},
{'名':'大卫'},
{'名':'约翰'},
]
要:
&LT; P&GT;尼克,大卫,约翰&LT; / P&GT;
但我无法弄清楚如何生成一个P。你怎么叫NG重复内的&LT; P&GT;
&LT; p NG重复=,在菜单项项&GT; {{item.name}}&LT; / P&GT;
一件事,将是有益的是建立一个地图过滤器,像这样:
myModule.filter('地图',函数(){
返回功能(输入,的propName){
返回input.map(函数(项目){
返回项目[作为propName]
});
};
});
这是映射到指定属性的简单的例子,你可以使它更看中和理解点符号等。现在这种情况,在你看来,你可以这样做:
&LT; P&GT;
{{(菜单项|图:'名')加入('')}}
&所述; / P&GT;
由于地图过滤器返回一个数组,它有一个内置的已经在Javascript中加入方法。
I have a pretty basic scenario (somewhat new to angular). I am trying to convert JSON:
[
{'name': 'Nick'},
{'name': 'David'},
{'name': 'John'},
]
To:
<p>Nick,David,John</p>
But I can not figure out how to generate a single "p." How do you call ng-repeat inside of the <p>
<p ng-repeat="item in menuItems">{{item.name}}</p>
One thing that would be helpful is creating a "map" filter, like so:
myModule.filter('map', function() {
return function(input, propName) {
return input.map(function(item) {
return item[propName];
});
};
});
That's the simple case of mapping to a named property, you could make it more fancy and understand dot notation, etc. Now with this, in your view you can do:
<p>
{{(menuItems | map:'name').join(',')}}
</p>
Because the map filter returns an Array, which has a built-in join method already in Javascript.
这篇关于逗号分隔&LT; P&GT;角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!