【发布时间】:2015-10-24 05:13:43
【问题描述】:
我有一个简单的对象字面量,它是这里显示的地址
address: {
country: String,
state: String,
city: String,
zip: String,
street: String
}
它在我通过 express.js 渲染函数传递的对象内部。
在我的模板页面中,我试图在这个对象内循环,如图所示:
<% for (var prop in artist.address ) { %>
<%- artist.address[prop] %>
<% } %>
输出数据但包含 ejs 函数,如下所示:
function () { return this.get(path); } function () { return this.get(path); } yafo 09988 jerusalem israel israeli [object Object] undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined [object Object] [object Object] function () { var self = this , hookArgs // arguments eventually passed to the hook - are mutable , lastArg = arguments[arguments.length-1] , pres = this._pres[name] , posts = this._posts[name] , _total = pres.length , _current = -1 , _asyncsLeft = proto[name].numAsyncPres , _next = function () { if (arguments[0] instanceof Error) { return handleError(arguments[0]); } var _args = Array.prototype.slice.call(arguments) , currPre , preArgs; if (_args.length && !(arguments[0] == null && typeof lastArg ===
那么我需要如何迭代我的对象?
【问题讨论】:
-
address实际上是mongoose.Schema和artist.address是mongoose.Document? -
不,艺术家是 mongoose.schema var artistSchema = mongoose.Schema({ address: { country: String, state: String, city: String, zip: String, street: String }, . ...
标签: node.js for-loop express ejs