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 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含