0

我需要动态填充一些文本框,一个数组包含标签第二个数组包含我想用来填充的值

Array ( [Enquiry] => Enquiry [Application Sent] => Application Sent [Application Received] => Application Received [Interview Booked] => Interview Booked [Offer Made] => Offer Made [Offer Accepted] => Offer Accepted [Deposit Paid] => Deposit Paid ) 1 

Array ( [0] => 10 [1] => [2] => [3] => [4] => [5] => 5 [6] => ) 1

文本框是基于第一个数组创建的,我需要检查第一个数组中的位置,并用第二个数组中相应索引的值填充文本框中的值。因此查询的值为 10,接受的报价为 5,依此类推。

如何在以下 smarty 代码中执行此操作?我以前从未真正与 smarty 合作过。

  <input type="hidden" id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}_multiselect"
name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}_multiselect" value="true">
{multienum_to_array string={{sugarvar key='options' string=true}} default={{sugarvar key='default' string=true}} assign="values"}
{$values|@print_r}
{multienum_to_array string={{sugarvar key='value' string=true}} default={{sugarvar key='default' string=true}} assign="vals"}
{$vals|@print_r} 

{foreach from=$values key=k item=item}

    {if @in_array($k, $vals)}
        {assign var=v value=true}
    {else}
        {assign var=v value=false}
    {/if}

    <input size="2" type="text" id="" name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}[]" value="{ {{sugarvar key='value' string=true}}.$item }" />&#37; &nbsp;<label>{ {{sugarvar key='options' string=true}}.$item }</label><br />

{/foreach}
4

1 回答 1

0

你为什么要创建 2 个数组?我认为创建如下所示的 1 个数组对您来说会更好

Array ( 
         [Enquiry] => '10' ,
         [Application Sent] => '', 
         [Application Received] => '',
         [Interview Booked] => '', 
         [Offer Made] => '', 
         [Offer Accepted] => '5', 
         [Deposit Paid] => '' 
     ) 

然后像下面这样处理数组:-

如果$myArray包含上述数组,则

{foreach from=$myArray key=k item=val}
   <li>{$k}: {$val}</li>
{/foreach}

$k 定义键和 $val 定义 $myArray 数组的值

于 2013-08-09T13:05:20.783 回答