我需要什么:
这是数组:
data: [
{
company_id: "42172",
Product_Name: "Intelligent Ethernet Access System (Ieas 05),In-Line Amplification
Systems,Intelligent Ethernet Access System (Ieas 03),Band Combiner Devicestcs infosys
polaris accenture fggghh ffghggghmnhg fghfggh fg fgfg f ffg fgfg bfggf fghg gghg
fgbfgg,Ethernet Access System,The Introductory Transport System,Intelligent Ethernet
Access System (Ieas 06),Top End Transport System,Intelligent Ethernet Access
System,Ethernet Aggregation Device,Our Mid Level Transport System",
Company_Website: "http://www.xkl.com/",
company_name: "XKL",
city_name: "Kirkland",
country_names: "USA",
comp_img: "http://10times.com/pics/company/3671/logo.jpg"
},
*如何从数组中获取前5个产品名称。
这是我的代码
{% if(item.Product_Name)|length < 300 %}
{% set foo = item.Product_Name|split(',') %}
{% for i in foo|slice(0, 4) %}
{{ i }}
{% if(loop.last)< 5 %}
,
{% endif %}
{% endfor %}
{% else %}
{% set foo = item.Product_Name|split(',') %}
{% for i in foo|slice(0, 5) %}
{{ i }}
{% if(loop.last)< 5 %}
,
{% endif %}
{% endfor %}
{% endif %}
考虑产品名称: -
line 1: a,
line 2 :b,
line 3 :c,
line 4:d,
line 5 :e
考虑前五个元素的字符长度是否大于300,那么i t限制条件,第5行不会发生。