Smarty中的Foreach

时间:2018-10-05 06:46:24

标签: smarty

我聪明的import React, { PureComponent } from 'react'; import { Radio, FormControlLabel } from '...'; export default class RadioOption extends PureComponent { handleChange = () => this.props.handleCompanySelect(this.props.company); render = () => { const { name } = this.props.company; return ( <FormControlLabel control={<Radio />} name={name} value={name} label={name} onChange={this.handleChange} /> ) } } 返回了以下数组:

{brands}

我需要此视图查看数组中的所有array (size=2) 0 => array (size=3) 'id' => string '98' (length=2) 'name' => string 'Adidas' (length=6) 1 => array (size=3) 'id' => string '168' (length=3) 'name' => string 'Agisko' (length=6) 。我该怎么写呢?

name

1 个答案:

答案 0 :(得分:1)

可以像在PHP代码中一样或使用点符号来访问关联数组值:

<ul>
    {foreach $brands as $brand}
        <li>{$brand['name']}</li>
    {/foreach}
</ul>

<ul>
    {foreach $brands as $brand}
        <li>{$brand.name}</li>
    {/foreach}
</ul>