[英]How to display twitter and instagram @ (usernames) as a profile name with meteor?
我正在嘗試使一個變量從2個差值中選擇,如果一個為null,則選擇另一個。
author: '@'+ user.services.instagram.username.toUpperCase() || user.services.twitter.screenName.toUpperCase()
當我嘗試在Twitter帳戶上發表評論時,這會導致錯誤。
TypeError: Cannot read property 'instagram' of undefined
這是一個短代碼
comment = _.extend(commentAttributes, {
userId: user._id,
// author: '@'+user.services.instagram.username.toUpperCase(),
author: '@'+ user.services.instagram.username.toUpperCase() || user.services.twitter.screenName.toUpperCase(),
submitted: formatDate(new Date())
});
user.services
變量是undefined
。 '@' + null
給出'@null'
,所以它總是真實的。 我找到了解決方案。 我試圖使用'same'變量拉動instagram和twitter的@句柄,因此可以將其用作配置文件名稱。 問題是Instagram正在使用services.instagram.username,而Twitter正在使用services.twitter.screenName
我可以解決編輯流星包的問題,但這不是一個完整的解決方案,而是基於this為'Account.onCreateUser'創建了條件。
所以我只是使profile.name保存用戶@而不是name。
if (service == 'instagram') {
if (!user.profile)
user.profile = {};
if (!user.profile.name)
user.profile.name = user.services[service].username;
}
if (service == 'twitter') {
if (!user.profile)
user.profile = {};
if (!user.profile.name)
user.profile.name = user.services[service].screenName;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.