ECSHOP模板js调用PHP数组

最近修改PHP东西(ecshop),遇到一个问题,诚恳求助各位高手:
1.在php页面里利用smarty模板赋值,部分代码如下:
 
    while ($row = $db->FetchRow($res))
    {
     if($cur==null)
     $cur=$row['template_id'];
     $modelrow[$row['template_id']]=$row['template_id'];
     $modelcontent[$row['template_id']]=trim($row['template_content']);     
     $modelplates[$row['template_id']]=$row['template_subject']." -$row[content_category]-".$row['template_subject_second'];
 //  echo         $modelcontent[$row['template_id']];
   
    }
$smarty->assign('cur', $cur);
$smarty->assign('modelrow', $modelrow);
$smarty->assign('modelplates', $modelplates);
$smarty->assign('modelcontent',$modelcontent);
/*end*/

$modelcontent 数组传递到前台的dwt模板中 在js函数中:
1、显示获取一个变量值temp=$("#temp").val(); (这个变量值为1、2、3之类的,获取没有问题。)
2、var a='{$modelcontent.temp}';第二步利用变量获取$modelcontent的一个元素值,但是为空,不知道怎么样才能获取到;我在测试的时候var a='{$modelcontent.1}'获取数组下标为1的还是能够获取到。

=======================================解决办法=========================================

上面的传递过去之后,在js里用alert(typeof({$modelcontent })),,得到的是function,应该不是我们想要的值,所以利用$modelcontent [temp],也无法获得相应的元素值,

$smarty->assign('modelcontent',js_encode($modelcontent));,这样就可以得到数组,利用变量temp获取到$modelcontent [temp]的对应值。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值