我正在开发Spotify应用程序.我能够登录并获取我的令牌.我的问题是我无法访问方法之外的变量.在这种情况下"getCurrentUser"
这是我的方法:
function getUser() {
if ($localStorage.token == undefined) {
throw alert("Not logged in");
} else {
Spotify.getCurrentUser().then(function(data) {
var names = JSON.stringify(data.data.display_name);
console.log(names)
})
}
};
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我在控制台上记录了名称,并且我在控制台中获得了正确的值.但是只有在我调用函数时getUser()才能在那里工作,undefined即使返回了names变量.
我需要$scope那个变量.
我试图获取类型为 bool 的所有属性的名称和值,似乎有效,但得到了错误的值。
这是我正在使用的代码:
signupItem.GetType().GetProperties()
.Where(p => p.PropertyType == typeof(bool) && (bool) p.GetValue(signupItem, null))
.Select(p => p.Name).ToList().ForEach(prop => {
var value = (Boolean) signupItem.GetType()
.GetProperty(prop).GetValue(signupItem, null);
html = (value) ?
html.Replace("{chkbox}", "<input type='checkbox' id='html' checked>") :
html.Replace("{chkbox}", "<input type='checkbox' id='html'>");
});
Run Code Online (Sandbox Code Playgroud)
但当尝试将其分配给变量时,它显示错误。
任何帮助,将不胜感激。