《30天App開發從0到1:APICloud移動開發實戰》第54頁
打開main.html,在apiready中添加一段代碼
api.addEventListener({ name: 'citySelected' }, function(ret, err){ $api.removeCls($api.byId("arrow"), 'active'); $api.html($api.byId("city"),ret.value.cityName); api.closeFrame({ name:'citySelectorFrame' }); }); 'active' ); $api.html ( $api.byId("city"), ret.value.cityName ) });
提示錯誤:Uncaught SyntaxError: Unexpected token ) at main.html : 117
博主發現
'active' ); $api.html ( $api.byId("city"), ret.value.cityName ) });
這里和前邊的
$api.removeCls($api.byId("arrow"),'active');
$api.html($api.byId("city"),ret.value.cityName);
重復了,刪除掉下邊的就好了
這里監聽citySelected事件,當選擇完城市后,會觸發后面的回調函數,關閉城市選擇Frame,之后修改箭頭的指向並更新城市名稱
如果發現更改完這,項目在APP Loader中運行時,選擇完后城市選擇Frame沒有關閉
可以檢查是否按課本P53頁下方所寫的
name: 'cityselectorFrame',
api.openFrame({ name: 'cityselectorFrame', url: './cityselector_frame.html', rect: { x: 0, y: headerH, w: 'auto', // 自動填充所在Window的寬度 h: 'auto' // 自動填充所在Window的高度 },
另:第48頁、49頁的<section>那段是重復的
希望Apicloud平台越做越好把
附上一個自己做的高仿課本開發App網上書店項目 傳送門