那么我如何控制dojo中页面内容的加载顺序
我在 UI 中使用 dojo,并且想按顺序加载页面内容的某些部分。例如,对于某只股票,我想加载股票的一般信息,例如股票代码、公司名称、关键统计数据等,以及包含最近 30 天开盘/收盘价的网格。不同的内容会分别从服务器获取。现在,我想首先加载网格,以便用户可以查看一些内容,然后开始加载关键统计数据,这是一个大型数据集,需要更长的时间来加载。我该怎么做。我试过: dojo.addOnLoad(function() {
startGrid(); //模拟网格启动函数,工作正常 getKeyStats(); //mock key stat getter 函数也可以正常工作 });
但是由于某种原因,dojo 正在加载 getKeyStats(),然后加载 startGrid(),并且顺序在这里似乎并不重要。那么如何才能随意控制加载顺序呢? 提前致谢!
大卫
I'm using dojo for our UI's, and would like to load certain part of page contents in sequence. For example, for a certain stock, I'd like to load stock general information, such as ticker, company name, key stats, etc. and a grid with the last 30 days open/close prices. Different contents will be fetched from the server separately. Now, I'd like first load the grid so the user can have something to look at, then, say, start loading of key stats which is a large data set takes longer time to load. How do I do this. I tried:
dojo.addOnLoad(function() {
startGrid(); //mock grid startup function which works fine
getKeyStats(); //mock key stat getter function also works fine
});
But dojo is loading getKeyStats(), then startGrid() here for some reason, and sequence doesn't seem be matter here. So how I can control the loading sequence at will?
Thanks in advance!
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
顺序并不重要,因为它们是异步请求;它们以与从服务器接收响应的顺序相同的顺序出现,这不一定与调用它们的顺序相同。
要以正确的顺序加载它们,请像平常一样发出请求。添加成功响应的回调,将响应数据以任意顺序放入共享存储桶中。一旦获得适当数量的响应(在回调结束时检查),开始按您喜欢的任何顺序将数据插入页面。
The sequence doesn't matter because they are asynchronous requests; they appear in the same order as responses were received from the server, which is not necessarily the same order as they were called in.
To load them in the correct order, make your requests as normal. Add a callback for a successful response that places the response data into a shared bucket in any order. Once you have the proper number of responses (check it at the end of your callback), start inserting data into the page in any order you like.
您可能需要查看 dojo.publish 并使用 pub sub 模式来松散地耦合这些事件以便您可以订购它们。 Pub sub 将允许您提出请求并侦听所有要触发的主题。这样,您可以异步调用请求,并将小部件加载到相应的位置,同时将它们设置为隐藏样式,并使用 pub sub 根据一系列主题出版物使它们可见。
you may want to look at dojo.publish and use a pub sub pattern to loosely couple these events so that you can order them. Pub sub will allow you to make the request and listen for all topics to fire. With this you could call the request asynchronously and load the widgets in there respective place while styling them hidden and use the pub sub to make them visible based on a sequence of topic publications.