近期在用mater-ui(react)開發一個用於手機端的網頁,遇到了一些坑,記錄一下。
提交表單的時候,按鈕無論如何也點擊不動,由於微信中瀏覽器的特殊性,一直沒找到合適的調試方式。
在chrome中和安卓上都運行的沒問題,到了ios平臺的微信網頁中沒報錯,按鈕就是點不動。
經過多次調試探究,在表單提交的回調函數中直接alert(err)
ws.insert(obj, function (err, result) {
if (err) {
console.log(" ws insert err:", err,"insert ws is::\n", worklist);
res = Meteor.call("logxxx" ,JSON.stringify(err) );
console.log(" res :", res);
//alert(JSON.stringify(err.reason))
alert("非常抱歉,出現異常 :",JSON.stringify(err));
} else {
console.log(" insert obj successs :", "");
FlowRouter.go('/myhome')
}
})
將以上代碼進行修改爲
if (err) {
alert(err);
} else {
FlowRouter.go('/myhome')
}
原因探析:
文檔中(如下)寫到,如果inserterror就會返回一個err object ,之前遇到的err都是一個obj對象,真正的錯誤信息在err.reason,這裏的err直接是錯誤信息,不需要json處理,這裏是個大坑.
collection.insert(doc, [callback])
Insert a document in the collection. Returns its unique _id.
Arguments
doc Object
The document to insert. May not yet have an _id attribute, in which case Meteor will generate one for you.
callback Function
Optional. If present, called with an error object as the first argument and, if no error, the _id as the second.
修改後,得到的錯誤信息是:
xxx不是時間類型。
“2015-08-18 08:08”
知道真相的我心中頓時覺得一萬隻草泥馬奔騰而過,chrome,安卓和wp都認識的格式到了你家平臺上就不認識了,呵呵呵。。。。
幾點總結:
1:搞特殊標準的瀏覽器大多特碼有病,但是又繞不過這個坑
2:用最原始的調試方式可能是最高效的,比如不加其他信息直接alert錯誤
3:此種錯誤可用服務器端打印的方式來排查,不一定好用
4:經驗主義害死人,多看文檔,但是又不能全信文檔。
5:據不可靠消息雙擊home殺死進程可清理微信瀏覽器的緩存。