Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a table like this:

<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>  

These variable {{ choice...}} may or may not have value. It is sequential though. The variable upto 3 can have values and none of have values after 3. If there's no value it comes like this:

water, pollution, hello, , , , , ,

I don't want to show comma if there's no value. How can I do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
232 views
Welcome To Ask or Share your Answers For Others

1 Answer

You could do something like this if you are seeking a jQuery solution (seeing you tagged 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);
    });
});

Proof of concept: http://jsfiddle.net/wPRNH/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...