【问题标题】:Adding a field to a Spotify list向 Spotify 列表添加字段
【发布时间】:2012-05-25 00:42:01
【问题描述】:

我正在尝试向 Spotify API 提供的列表添加一个字段。

这是我创建列表的代码:

var playList_view = new views.List(playlist_test, function(track) {
                return new views.Track(track, views.Track.FIELD.NAME | 
                                            views.Track.FIELD.ARTIST | 
                                            views.Track.FIELD.ALBUM);
            });

$('#tracks').append(playList_view.node);

我不知道如何通过函数将其添加到视图中,所以我在事后添加它。如果有更好的方法,请告诉我。

这是尝试(部分成功):

$('.sp-list a').append("<span>Test</span>");

这会为屏幕上显示的所有曲目正确地在其他列的右侧添加一列。当我在列表中向下滚动时出现问题。它似乎正在刷新并且html被重写。我认为这里的解决方案是在视图创建时将代码添加到函数中,或者观察某种更改/刷新事件。不幸的是,我不确定这些事件是什么,也不确定找到它们列表的好地方。

感谢任何帮助!

谢谢, 凯文

【问题讨论】:

    标签: javascript list spotify


    【解决方案1】:

    这样做的一种方法是在 scroll 事件上使用处理程序来检测列表已被滚动,然后重新添加该字段。但是,您需要注意它不会最终将其添加到已经添加它的行中,否则您最终会得到重复的字段。这似乎可行:

    function addCustomField() {
        $('.sp-list a.sp-item').each(function() {
            if($(".custom-field",$(this)).length == 0) // check field doesn't already exist
            {
                $(this).append("<span class=\"custom-field\">Test</span>");
            }
        });
    }
    
    setTimeout(function() {
        addCustomField(); // Add the custom field to the visible tracks
        $('.sp-list').scroll(addCustomField); // Register the scroll handler
    },10);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-20
      • 2012-04-18
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 2012-01-21
      • 1970-01-01
      相关资源
      最近更新 更多