我通過編輯mithril.js源碼修復了這個問題。我必須將電話打到m.endComputation
底部的finally
區塊。
我不明白爲什麼try/catch
不起作用,爲什麼這finally
是必需的。但我想我會把它作爲一個錯誤發佈。
xhrOptions.onload = xhrOptions.onerror = function(e) {
try {
e = e || event;
var unwrap = (e.type === "load" ? xhrOptions.unwrapSuccess : xhrOptions.unwrapError) || identity;
var response = unwrap(deserialize(extract(e.target, xhrOptions)), e.target);
if (e.type === "load") {
if (type.call(response) === ARRAY && xhrOptions.type) {
for (var i = 0; i < response.length; i++) response[i] = new xhrOptions.type(response[i])
}
else if (xhrOptions.type) response = new xhrOptions.type(response)
}
deferred[e.type === "load" ? "resolve" : "reject"](response)
}
catch (e) {
m.deferred.onerror(e);
deferred.reject(e)
} finally {
// This is now in a finally block
if (xhrOptions.background !== true) m.endComputation()
}
};
我認爲可能發生的是該錯誤阻止了m.redraw的執行。米索里爾的m.request承諾不包括一個捕獲 - 你可以使用一個更好的ajax庫,有一個捕獲(我愛mithril但m.request是一團糟),或包裝你的m.request在承諾和捕獲任何錯誤。然後你可以用一個空數組解決並手動調用m.redraw(我不知道這是否有必要)。 – dcochran
@dcochran我在這裏發現了具體的問題:http://i.imgur.com/HaXEKBO.png 'deserialize'是'JSON.parse',它實際上在一個'try'塊中......怎麼可能這個錯誤沒有被捕獲!? http://i.imgur.com/kZ74Arv.png –