Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 余烬数据和余烬状态管理器_Ember.js_Ember Data - Fatal编程技术网

Ember.js 余烬数据和余烬状态管理器

Ember.js 余烬数据和余烬状态管理器,ember.js,ember-data,Ember.js,Ember Data,我有一个应用程序,它使用余烬数据分发数据,并使用StateManager驱动其全局状态。因为加载数据是异步的,所以我想知道如何捕获表示所有数据都已加载的事件。 确切地说,我有一个名为“加载”的状态,其中我加载数据时使用: App.store.find(App.Model, ....) 加载模型后,我会进行一些后期处理。这是在名为“后处理”的“加载”子状态中完成的。当每个modele都得到一个“didLoad”事件时,我过渡到“后处理”: 加载和后处理每个数据时,应用程序应过渡到与“加载”级别相

我有一个应用程序,它使用余烬数据分发数据,并使用StateManager驱动其全局状态。因为加载数据是异步的,所以我想知道如何捕获表示所有数据都已加载的事件。 确切地说,我有一个名为“加载”的状态,其中我加载数据时使用:

App.store.find(App.Model, ....)
加载模型后,我会进行一些后期处理。这是在名为“后处理”的“加载”子状态中完成的。当每个modele都得到一个“didLoad”事件时,我过渡到“后处理”:

加载和后处理每个数据时,应用程序应过渡到与“加载”级别相同的另一个“编辑”状态:

我应该捕捉什么样的事件来实现转换?余烬数据存储是否对此有回调?

尝试观察”content@each.isLoaded并调用模型的arrayController中的stateManager.sent(“编辑”)。比如:

App.ModelArrayController.reopen({
    didLoadAllContent: function () {
        if (content.everyProperty('isLoaded')) {
            stateManager.transitionTo('editing');
        }
    }.observes("content.@each.isLoaded")
)}

当然,这可能是一个更简单的方法。或者更正确的方法…

当使用余烬数据时,find方法返回一个数组代理。您可以观察该对象上的isLoaded字段

var data = App.store.find(App.Model, {});
data.addObserver('isLoaded', function() {
    if (data.get('isLoaded')) {
        ....
    }
});
但请记住通过removeObserver清理您的观察者

我将此实用程序添加到内置的ember数据记录数组中

DS.RecordArray.reopen({
    onLoad: function(callback) {
        if (this.get('isLoaded')) {
            callback(this);
        } else {
            var that = this;
            var isLoadedFn = function() {
                if (that.get('isLoaded')) {
                    that.removeObserver('isLoaded', isLoadedFn);
                    callback(that);
                }
            }

            this.addObserver('isLoaded', isLoadedFn);
        }

        return this;
    }
}
所以现在你可以做了

App.store.find(App.Model, {}).onLoad(function(data) {
    ....
});
你也可以这样做

init: function() {
    this.set('data', App.store.find(App.model, {}));
},

onData: function() {
    if (this.get('data.isLoaded')) {
        ...
    }
}.observes('data.isLoaded')

通常,模型的状态将由路由处理

模型钩子执行store.find。

路径的模型解析(加载)后,将调用afterModel挂钩。

App.store.find(App.Model, {}).onLoad(function(data) {
    ....
});
init: function() {
    this.set('data', App.store.find(App.model, {}));
},

onData: function() {
    if (this.get('data.isLoaded')) {
        ...
    }
}.observes('data.isLoaded')