dongshai1944 2012-09-05 15:30
浏览 51
已采纳

php爆炸不能在javascript模板中工作

I'm aware of some posts already dealing with the same topic.

Following are the links:

Javascript Template Engine Use with jQuery

What is x-tmpl?

I'm trying to incorporate a php explode function into a javascript template. The plugin is jQuery-File-Upload from blueimp @ https://github.com/blueimp/jQuery-File-Upload/downloads i downloaded off GitHub.

Following is part of my code i'm trying to execute and make it work.

         <!-- The template to display files available for download -->
         <script id="template-download" type="text/x-tmpl">
         {% for (var i=0, file; file=o.files[i]; i++) { %}
             <tr>
                <td>
                     <?php echo "{%=file.name%}"; ?> //{%file.name%} contains a string seperated by underscores
                     <?php $file_name_long = '{%=file.name%}'; ?>
                     <?php $file_name = explode ('_' , $file_name_long); ?>
                     <?php print_r($file_name); ?>
                </td>
             </tr>
               ...
               ...

I'm able to make $file_name print out as an array but I'm not able to get it seperated by the underscore within my file.name. the printed array contains the whole string as per file.name.

I'm not sure if this is even possible. I've been trying all day. If this is not do-able or logically incorrect, do let me know so that i can stop trying to want to make this work. Thanks and appreciated.

  • 写回答

2条回答 默认 最新

  • doudouwd2017 2012-09-05 15:41
    关注

    your are trying to read javascript values in your php code.

    {%=file.name%} is simply a string to php and contains no actual filenames when your php renders the output. so your print_r() would output {%=file.name%} which then gets translated into your filename later in the browser after the whole php processing is done.

    try implementing this stuff in javascript alone.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题