9

我有这样的数组

{
     "sCode":"05",
     "sCodeName":"critical_tight_connection",
     "iSeverity":1,
     "aData":{
         "iLevelOfDetailt":2,
         "iDuration":35,
         "sLabel":"Labai trumpas pers\u0117dimas, 35 min.",
         "sLink":""
     }
}

我正在用 smarty 打印他(数组未序列化,我已经为您的方便做了)

{if !empty( $aSegment.aNotices.aStop )}
    <ul>
        {foreach from=$aSegment.aNotices.aStop item=aNotice}
            <li>
                <img class="{$aNotice.sCodeName}" />
                {$aNotice.sLabel}
            </li>
        {/foreach}
    </ul>
{/if}

如果 aNotices.aStop.sCode 中存在“05”,如何使用 smarty 检查?(在 foreach 循环之前)

试过这个

{if in_array('05', $aSegment.aNotices.aStop)}
    exist
{/if}
4

3 回答 3

26

你可以使用这个:

{if '05'|in_array:$aSegment.aNotices.aStop}EXIST{/if}
于 2013-01-20T00:27:55.857 回答
3

你的意思是这样的吗?

{if $aNotice.sCode == '05'} ....
于 2013-01-18T14:26:31.683 回答
0

谢谢hek2mglJeff Bic,修改了你的答案,这很好用:

{if !$aSegment.aNotices.aStop|@count gt 0}
    {t lang='en'}Stop duration{/t}{if $server.lang != 'en'} / {t}Stop duration{/t}{/if}: {$aSector.aStops.$iSegmentIndex|mins_to_time}
{/if}
于 2013-01-21T08:29:00.183 回答