为什么我的Dojo ContentPane在加载内容后没有解决它的承诺?
Why isn't my Dojo ContentPane resolving its promise after loading content?
我正在努力修复一个相对较旧的应用程序中的错误,该应用程序是为旧版本的Dojo编写的,即使在那时也从未工作过,现在运行在Dojo 1.10上。有些应用程序逻辑不太适合当前的Dojo范例,但有些对我来说似乎是正确的,我不明白为什么它没有像预期的那样工作。
有一个基于dijit.layout.ContentPane
的自定义小部件。添加的方法似乎都没有破坏原来的方法,只是通过主题将一些滚动事件连接到其他小部件。还有一个主题可以触发ContentPane中的地址更改。
相关的位看起来像这样:
// The widget is initially setup declarative markup
var contentPaneWidget = registry.byId("<content_pane_id>");
// This subscribe is actually part of the custom widget code, but
// the topic subscription and resulting set() work, so I don't think
// where this is run is relevant to the question
topic.subscribe("navEvent", function(url) {
contentPaneWidget.set("href", url).then(function() {
topic.publish("navComplete", url);
}, function(err) {
console.log("Navigation error:", err);
});
});
// This topic subscription in another widget should get fired after
// content loads in the ContentPane based widget
topic.subscribe("navComplete", function(url) {
console.log("Navigation finished:", url);
});
// Test the chain ov events by firing off a new URL to the nav topic
topic.publish("navEvent", "<new_content_url>");
内容加载正常。解析并加载URL,并用下载的内容更新内容窗格。问题是.then()
函数永远不会触发,因此navComplete主题永远不会激活。有趣的是,不只是成功函数没有触发,错误函数也没有触发。
如果我手动解决承诺(通过将.resolve()
添加到链的末端或稍后在代码中调用contentPaneWidget.onLoadDeferred.resolve()
或手动从控制台),那么一切都按预期发射。文档中set("href", ...)
返回一个promise,这个promise在网络操作和内容渲染完成后永远不会被解决。
这是不正确的用法吗?Dojo中有bug吗?还是我在这个应用程序代码中寻找其他一些小妖精?
在try/catch
内延迟的解析
参见https://github.com/dojo/dijit/blob/master/layout/ContentPane.js#L440
我猜你正在加载的内容触发一个JS错误,这个错误被try/catch
吞噬,因此你看不到任何事情发生…
- 如何在解决承诺之前和之后验证值
- EmberJS:在成功处理请求时解决承诺
- 蓝鸟没有正确解决承诺
- 使用 $http.post 和 res.redirect,而不解决承诺
- 如何在解决承诺后从承诺对象获取值
- 在解决承诺 AngularJS/ES6 后检索存储在服务中的数据
- CSV 完成读取后,如何解决承诺
- 茉莉花间谍和解决承诺
- 如何在轮询时不断解决Q承诺
- 拒绝并解决Q承诺
- 基于另一个承诺解决承诺
- 立即解决承诺
- 通过离子/ui路由解决承诺
- 我可以选择只在if语句的一部分中解决承诺吗
- 开玩笑-在测试前解决承诺
- 多次解决承诺
- 让双方都期待解决承诺
- 问美元.所有这些都在解决承诺之前被调用
- 在angular中解决承诺
- Angularjs单元测试解决承诺