doufan3408 2018-06-20 12:21
浏览 53
已采纳

Fileupload与选定的选定选项相结合

I'm using jQuery FileUpload (by BlueImp). This plugins uses x-tmpl as templating. I want a tags input field to contain options filled by a PHP variable. I'm trying to make a prototype by just adding some dummy text.

Code:

  <td id="{%=file.id||''%}" class="tagsInput" style="display:none;">
               <select data-placeholder="Type &apos;C&apos; to view" multiple class="chosen-select-no-results" tabindex="11">
                    <option value=""></option>
                    <option  {% if(strpos(file.tags, "American Black Bear") !== FALSE) { echo 'selected'; } %{>American Black Bear</option>
                    <option  {% if(strpos(file.tags , "Asiatic Black Bear") !== FALSE) { echo 'selected';  }  %{>Asiatic Black Bear</option>
                    <option  {% if(strpos( file.tags , "Brown Bear") !== FALSE) { echo 'selected'; }  %{>Brown Bear</option>
                    <option>Giant Panda</option>
                    <option>Sloth Bear</option>
                    <option>Sun Bear</option>
                    <option>Polar Bear</option>
                    <option>Spectacled Bear</option>
                </select>
        </td>

However this code gives me:

VM34875:3 Uncaught SyntaxError: Invalid or unexpected token

This error is generated by tmpl.min.js.

How can I check for previously selected options that are stored in file.tags with x-tmpl?

  • 写回答

1条回答 默认 最新

  • douzhong3038 2018-06-20 14:20
    关注

    Alright.. So I figured out that my post was full of wrong templating. First of all I had some mistakes with {% %} %} %{ format. Besides I messed up by thinking {% %} allowed me to enter PHP code. Everything within the brackets will remain JS.

    This got it working for me:

    <td id="{%=file.id||''%}" class="tagsInput" style="display:none;">
        <select data-placeholder="Type &apos;C&apos; to view" multiple class="chosen-select-no-results" tabindex="11">
            <option value=""></option>
            {% for (var t=0; t < tagsz.length; t++) {  %}
            {% if(file.tags != '' && file.tags.indexOf(tagsz[t]) >= 0) { %} <option selected>{%=tagsz[t]%}</option> {% } else { %} <option>{%=tagsz[t]%}</option> {% } %}
            {% } %}
        </select>
    </td>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码