问题描述
我正在尝试在带有 for 循环的 Django 项目中每页放置多个波形。我创建了一组 wavesurfers(每个波形一个)。它们渲染得很好,但只有最后的 wavesurfers 播放。
这是创建每个 wavesurfer 的函数:
<script>
var wavesurfers_array=[];
function wavesurfer_creator(i_,url){
w= WaveSurfer.create({
container:'#waveform'+ i_,});
w.load(url);
wavesurfers_array.push(w);
return w;
}
var i=0; //counter of wavesurfers
这是 Django 模板语言中的 for 循环,用于构建每个波形
{% for song in song_list %}
<div>
<a>{{ song.name }}</a>
<div id="waveform"></div>
<script type="text/javascript">
$("#waveform").attr({id:"waveform"+i}); //change id of waveform div to be compitable with each wavesurfer
wavesurfer_creator(i,url);
wavesurfers_array[i].on('ready',function () {
wavesurfers_array[i].play();
});
i+=1;
</script>
</div>
{% endfor %}
我是编程新手。我已经尝试了几天来解决这个问题。如果你们能帮助我,我将不胜感激:)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)