0

次のようなテーブルがあります。

<table class="table table-bordered">  
        <thead>  
          <tr>  
            <th></th>
            <th>Project Name</th>
            <th>Tape-ID</th>  
            <th>Video Type</th>  
            <th>Date Created</th>  
            <th>Director</th>  
            <th>Camera Person</th>
            <th>Editor</th> 
            <th>Tag</th> 
          </tr>  
        </thead>  
        <tbody>  
        {% load endless %}

    {% paginate 8 a %}
        {% for choice, i in a %}
          <tr>  
            <td><input type="checkbox" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}"  onchange="checkChecked()" /></td>
            <td>{{ choice.name }}</td>
            <td>{{ choice.tape_id }} </td>  
            <td>{{ choice.video_type }}</td> 
            <td>{{ i }}</td>  
            <td>{{ choice.director }}</td>  
            <td>{{ choice.cameraman }}</td>  
            <td>{{ choice.editor }}</td> 
            <td>{{ choice.tag1 }}, {{ choice.tag2 }}, {{ choice.tag3 }}, {{ choice.tag4 }},
            {{ choice.tag5 }}, {{ choice.tag6 }}, {{ choice.tag7 }}, {{ choice.tag8 }}, 
            {{ choice.tag9 }}, {{ choice.tag10 }}


            </td>   
          </tr>  
       {% endfor %}

        </tbody>  
      </table>  

これらの変数{{ choice...}}には、値がある場合とない場合があります。シーケンシャルですが。3 つまでの変数は値を持つことができ、3 より後の値を持つことはできません。値がない場合は、次のようになります。

water, pollution, hello, , , , , ,

値がない場合はコンマを表示したくありません。これどうやってするの?

4

4 に答える 4

0

その結果を取得した後、正規表現を使用できますs = s.replace(/[,\s]{2,}/,"");

于 2013-04-02T10:27:59.793 に答える
0

jQuery ソリューションを探している場合は、次のようなことができます (jQuery にタグを付けているのを見てください)。

$(function() {
    // get rows
    $('table.table tbody tr').each(function() {
        // get last cell in each row
        var cell = $(this).find('td:last');
        // replace trailing spaces and commas
        var text = cell.html().replace(/(,|\s)+$/, '');
        // update cell display
        cell.html(text);
    });
});

概念実証: http://jsfiddle.net/wPRNH/

于 2013-04-02T10:26:38.273 に答える