我使用momentjs在一个角度指令中得到了一个简单的函数。它为日历构建了一周。我尝试为预订设置不可用日期。
使用Chrome控制台我认为我使用以下方法解决了问题:indexOf();
我遇到的问题是当我在push方法中移动代码时它返回date is undefined (.date.format('YYYY-MM-DD'))
:
function _buildWeek(date, month) {
var days = [];
for (var i = 0; i < 7; i++) {
days.push({
name: date.format("dd").substring(0, 1),
number: date.date(),
isCurrentMonth: date.month() === month.month(),
isToday: date.isSame(new Date(), "day"),
date: date,
unavailable: dealerUnAvailabilityDates[0].daysOff.indexOf(days[days.length-1].date.format('YYYY-MM-DD')) !== -1
});
date = date.clone();
date.add(1, "d");
}
console.log(days);
return days;
}
我猜这个问题是&#39; date&#39;是对象的一部分,因此在创建对象之前不能使用它。它试图使用自己。\
我该如何解决这个问题?
答案 0 :(得分:0)
问题是,当您尝试在每次迭代中使用days[days.length - 1]
时,date
尚未填充。但是,您可以安全地使用var days = [];
for (var i = 0; i < 7; i++) {
days.push({
name: date.format("dd").substring(0, 1),
number: date.date(),
isCurrentMonth: date.month() === month.month(),
isToday: date.isSame(new Date(), "day"),
date: date,
unavailable: dealerUnAvailabilityDates[0].daysOff.indexOf(date.format('YYYY-MM-DD')) !== -1
}); // use date directly here --^
date = date.clone();
date.add(1, "d");
}
对象本身,因为它仍然是您想要的:
//GameViewController.swift
class GameViewController: UIViewController, FBInterstitialAdDelegate {
let interstitialFBAD: FBInterstitialAd = FBInterstitialAd(placementID: "65543456456456_454345345454534")
override func viewDidLoad() {
super.viewDidLoad()
}
//CALL THIS IN MY GAMESCENE.
func loadFBInterstitialAd() {
interstitialFBAD.delegate = self
interstitialFBAD.loadAd()
}
func interstitialAdDidLoad(interstitialAd: FBInterstitialAd!) {
interstitialFBAD.showAdFromRootViewController(self)
}
//GameScene.swift
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let location = touch.locationInNode(self)
let node = self.nodeAtPoint(location)
if node.name == "retry" {
GameViewController().loadFBInterstitialAd()
}
}
}