0

Jquery Raty プラグインをダウンロードしました: https://github.com/wbotelhos/raty

次に、このフォルダー構造を {{static_url}}js フォルダーにインストールし、Raty という名前を付けました。

次に、次のようにテンプレートにインポートし、画像が保存されている場所としてパスを配置しました。

  <script type="text/javascript" charset="utf-8" src="{{ STATIC_URL }}js/raty/js/jquery.raty.min.js"></script>
  <script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
         $('.thingrating').each(function(index){
          $(this).raty({
            readOnly:  false,
            path: "{{ STATIC_URL }}js/raty/img/",
            start: $(this).children("span:first").text(),
            click: function(score, evt) {
                var vote_url = "rate/" + this.attr('id').substring(2) + "/" + score + "/";
                $.ajax({
                  url: vote_url,
                  success: function(){
                    alert('vote successful');
                  }
                });
            }
          });
        });
    });
  </script>

これは正しいです?テンプレートで機能していることがわからないので、スクリプトを保存してテンプレートにインポートするこのプロセスが正しいことを確認してから、何が問題なのかを解読し続けたいと思います...

これが私のテンプレートの残りの部分です:

{% block body %}
    <h2>Things</h2>
        <div class="block" id="block-tables">
          <div class="content">
            <p></p>
            <div class="inner">
                <table class="table">
                  <tr>
                    <th class="first">Name</th>
                    <th class="last">Rating</th>
                  </tr>
                  <tr class="odd">
                    <td>{{ item.modelname }}</td>
                    <td><div class="thingrating" id="t_{{ item.id }}"><span style="display:none;">{{ score }}</span></div></td>
                  </tr>
                </table>
                <div class="actions-bar wat-cf">       
                </div>
            </div>
          </div>
        </div>
{% endblock %}
4

1 に答える 1

1

このjsfiddleデモを見てください。それは正常に動作します(初期スコアを定義したい方法を理解しているstartので、変更する必要があるように見えることを除いて)。score画像へのパスが間違っていても、まったく壊れません。画像へのパスが間違っている場合、ブラウザーは使用できない画像のデフォルト アイコンを表示するだけです。{{static_url}}変数に何が入っているかわかりません。「http://example.com/static」のようなものが含まれている場合は、その後にスラッシュを追加する必要があります。

考えられる問題 - rate のスクリプト タグが jQuery の前に表示されます。$(document).readyまたは、イベントが発生したときにテンプレート処理の結果がページに表示されません。

于 2012-10-29T16:09:56.570 に答える