我有一个位置模型和一个记录器模型。我希望能够将两个数据集的所有数据传递给我的视图模型。我该如何访问它们,但因为我觉得他们不是在范围,因为我越来越不确定的错误,因为我打电话“所有”如何从控制器访问多个模型
https://gist.github.com/3998302
var Main = function() {
this.index = function (req, resp, params) {
var self = this;
var data = {};
geddy.model.Locations.all(function(err, locations) {
data.locations = locations;
geddy.model.Recorders.all(function(err, recorders) {
data.recorders = recorders;
self.respond({params: params, data: data}, {
format: 'html'
, template: 'app/views/locations/index'
}
});
}););
};
};
exports.Main = Main;
错误片段:
timers.js:103
if (!process.listeners('uncaughtException').length) throw e;
^
TypeError: Cannot call method 'all' of undefined
at index (G:\code\PeopleTracker\app\controllers\main.js:23:24)
at controller.BaseController._handleAction.callback (C:\Users\Chris\AppData\Roaming\npm\node_modules\geddy\lib\base_
controller.js:387:22)
正确:JavaScript并不像Perl那样“自动化”对象。将一个属性赋值给一个未定义的变量不会自动将该变量转换为对象引用。 – ebohlman
我改变了这一点,它仍然给我一个错误。 timers.js:103 if(!process.listeners('uncaughtException')。length)throw e; ^ TypeError:无法在index(G:\ code \ PeopleTracker \ app \ controllers \ main.js:23:24)处调用未定义的 方法'all' at controller.BaseController._handleAction.callback(C:\ Users \ Chris \ AppData \ Roaming \ npm \ node_modules \ geddy \ lib \ base_ controller.js:387:22) – cmp