问题描述
我正在研究Spotify应用,并尝试从数据库中存储的一些信息中创建一个views.List对象.初始加载时,会进行POST以获取必要的信息.我将其存储在localstorage中,因此每个后续请求都可以避免访问数据库并在本地检索对象.尽管发生了什么事,但是我从本地存储数据创建的List对象却变成空白,而POST请求也很好.
I'm working on a Spotify app and trying to create a views.List object from some stored information in our database. On initial load, a POST is made to get the necessary info. I store this in localstorage so each subsequent request can avoid hitting the database and retrieve the object locally. What's happening though is the List objects I create from localstorage data come up blank, while the POST requests work just fine.
这是我用来创建列表的代码段:
Here is the snippet I'm using to create the list:
var temp_playlist = models.Playlist.fromURI(playlist.uri);
var tempList = new views.List(temp_playlist, function (track) {
return new views.Track(track, views.Track.FIELD.STAR |
views.Track.FIELD.NAME |
views.Track.FIELD.ARTIST |
views.Track.FIELD.DURATION);
});
document.getElementById("tracklist").appendChild(tempList.node);
第一行中的
playlist.uri是我从POST或从本地存储中检索的内容.在两种情况下,除tempList.node外,所得的views.List对象(tempList)看起来相同.从localstorage检索到的值显示console.log中的innerHTML,innerText,outerHTML和externalText的这些值:
playlist.uri in the first line is what I'm retrieving either from a POST or from localstorage. The resulting views.List object (tempList) looks identical in both cases except for tempList.node. The one retrieved from localstorage shows these values for innerHTML, innerText, outerHTML, and outerText in console.log:
innerHTML: "<div style="height: 400px; "></div>"
innerText: ""
outerHTML: "<div style="height: 400px; "></div>"
outerText: ""
而通过POST检索到的数据具有完整的数据:
Whereas the one retrieved via POST has the full data:
innerHTML: "<div style="height: 400px; "><a href="spotify:track:07CnMloaACYeFpwgZ9ihfg" class="sp-item sp-track sp-track-availability-0" title="Boss On The Boat by Tosca" data-itemindex="0" data-viewindex="0" style="-webkit-transform: translateY(0px); ">....
innerText: "3Boss On The BoatTosca6:082....
等等.
任何帮助将不胜感激
推荐答案
使用本地存储,我这样做是这样的:
Using, the local storage, I did it this way :
sp = getSpotifyApi(1);
var m = sp.require("sp://import/scripts/api/models");
var v = sp.require("sp://import/scripts/api/views");
var pl;
pl = m.Playlist.fromURI(uri);
var player = new v.Player();
player.track = pl.get(0);
player.context = pl;
var list = new v.List(pl);
XXXXX.append($(list.node));
希望,对我有用,这会有所帮助
Hope, it will help, as it's working for me
这篇关于从localStorage数据创建的Spotify列表对象显示为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!