正如您在这个jsbin中看到的,我正在尝试执行以下操作:
- 加载一些数据。数据是从 加载的
FIXTURE
,很慢,因为我们latency
在FIXTURE
. - 在加载数据时,我想显示一些简单的文本:
Loading ...
- 收到数据后,显示带有真实数据的插座。
我尝试了controllers.nodesIndex.isUpdating
, isLoading
,isUpdated
.isLoaded
和其他几种变体,但这不起作用。我如何对“数据准备就绪”事件做出反应?
编辑
我也尝试过使用属性绑定dataLoaded
;在路由中,当接收到数据时,我手动更新属性。但这也行不通。我收到几条错误消息:
Uncaught Error: Something you did caused a view to re-render after it rendered but before it was inserted into the DOM.
Assertion failed: Emptying a view in the inBuffer state is not allowed and should not happen under normal circumstances. Most likely there is a bug in your application. This may be due to excessive property change notifications
Uncaught Error: You cannot modify child views while in the inBuffer state
这是模板:
<div id="legend" class="">
<legend class="">Nodes <span class="badge">{{controllers.nodesIndex.length}} records</span></legend>
</div>
<!-- Just to get visual feedback when the data gets loaded -->
{{outlet}}
{{#if controllers.nodesIndex.dataLoaded}}
<!-- This should only be shown when the data is ready -->
{{outlet}}
{{else}}
Loading ...
{{/if}}
</fieldset>
</form>
</article>
这是控制器:
App.NodesIndexController = Ember.ArrayController.extend({
dataLoadedBinding: 'App.nodesLoaded'
});
这是路线:
App.NodesIndexRoute = Ember.Route.extend({
model: function() {
return App.Node.find().then(function(data) {
console.log('Data received > data=%o', data);
App.set('nodesLoaded', true);
return data;
});
}
});