对控制器/视图初始化事件做出反应

时间:2013-07-29 06:54:08

标签: ember.js

正如您在此jsbin中所看到的,我正在尝试执行以下操作:

  1. 加载一些数据。数据是从FIXTURE缓慢加载的,因为latency中的FIXTURELoading ...
  2. 在加载数据时,我想显示一些简单的文字:controllers.nodesIndex.isUpdating
  3. 收到数据后,请显示包含实际数据的商店。
  4. 我尝试使用isLoadingisUpdated.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&nbsp;&nbsp;&nbsp;<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;
            });
        }
    });
    

    这就是路线:

    {{1}}

1 个答案:

答案 0 :(得分:2)

在加载内容的句柄中提供备用标记的规范方法似乎是控制器的isUpdating属性content

{{#if content.isUpdating}}
   {{!-- content markup here --}}
{{else}}
   {{!-- Loading message here --}}
{{/if}}