0

I can reference my models like this in client scripts:

var myModels = app.models._values;
console.log(myModels[0].name);

The console shows:

Tue Apr 04 11:56:21 GMT-400 2017 Employees

But when I try this in a server script, I get an error when I log to the console (I don't get an error on assignment) (also _values does not come up as an option in code completion, but my models are all listed):

TypeError: Cannot read property "0" from undefined

So, it looks like _values is not implemented in server scripts.

How do I access my list of models in server-side scripting?

4

1 回答 1

2

这是一个例子:

/**
 * Prints names of all models.
 */
function printModels() {
  var modelNames = Object.getOwnPropertyNames(app.models);
  console.log(modelNames);

  for (var i = 0; i < modelNames.length; i++) {
    modelName = modelNames[i];
    console.log(app.models[modelName].newQuery().run().length);
  }
}
于 2017-04-04T17:54:36.160 回答