2

Estoy intentando recorrer un json en jade pero tengo problemas , pues me salen data basura.

usuarios={ _id: 57e66c6b0d38b61f3c0e626b, name: 'asdas', lastName: 'dasdasd', userName: 'dasd', password: 'ada', __v: 0 },{ _id: 57e66e16228d2f0674a90af5, name: 'dasdsad', lastName: 'asdasd', userName: 'dsadas', email: 'xxxxxxx', password: 'kevincito11', __v: 0 }}

En jade hago lo siguiente para recorrer los usuarios

for user in usuarios
   p #{user}

Hasta ahi todo bien , me saca todos los usuarios en orden

Ahora quiero recorrer el json para sacar los campos

for user in usuarios
  for val,key in user
     p #{key}:#{val}

Deberia salir el campo y su valor, pero me sale un monton de cosas innecesarias

[object Object]:$__

false:isNew

:errors

[object Object]:_doc

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 , _asyncsDone = function(err) { if (err) { return handleError(err); } --_asyncsLeft || _done.apply(self, hookArgs); } , handleError = function(err) { if ('function' == typeof lastArg) return lastArg(err); if (errorCb) return errorCb.call(self, err); throw err; } , _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 === 'function')) hookArgs = _args; if (++_current < _total) { currPre = pres[_current] if (currPre.isAsync && currPre.length < 2) throw new Error("Your pre must have next and done arguments -- e.g., function (next, done, ...)"); if (currPre.length < 1) throw new Error("Your pre must have a next argument -- e.g., function (next, ...)"); preArgs = (currPre.isAsync ? [once(_next), once(_asyncsDone)] : [once(_next)]).concat(hookArgs); return currPre.apply(self, preArgs); } else if (!_asyncsLeft) { return _done.apply(self, hookArgs); } } , _done = function () { var args_ = Array.prototype.slice.call(arguments) , ret, total_, current_, next_, done_, postArgs; if (_current === _total) { next_ = function () { if (arguments[0] instanceof Error) { return handleError(arguments[0]); } var args_ = Array.prototype.slice.call(arguments, 1) , currPost , postArgs; if (args_.length) hookArgs = args_; if (++current_ < total_) { currPost = posts[current_] if (currPost.length < 1) throw new Error("Your post must have a next argument -- e.g., function (next, ...)"); postArgs = [once(next_)].concat(hookArgs); return currPost.apply(self, postArgs); } else if (typeof lastArg === 'function'){ // All post handlers are done, call original callback function return lastArg.apply(self, arguments); } }; // We are assuming that if the last argument provided to the wrapped function is a function, it was expecting // a callback. We trap that callback and wait to call it until all post handlers have finished. if(typeof lastArg === 'function'){ args_[args_.length - 1] = once(next_); } total_ = posts.length; current_ = -1; ret = fn.apply(self, args_); // Execute wrapped function, post handlers come afterward if (total_ && typeof lastArg !== 'function') return next_(); // no callback provided, execute next_() manually return ret; } }; return _next.apply(this, arguments); }:$__original_save

¿En que me estoy equivocando?

2 respuestas 2

1

Prueba con estas dos maneras:

div
  each val, index in usuarios
    p= index + ': ' + val



for val,key in usuarios
  p #{key}:#{val}
0

No hay mucha documentación sobre los maps:

var usuarios = [
    {id:57e6,name:'asdas',lastName:'dasdasd',password:'ada'},
    {id:57e6,name:'apas',lastName:'dasdasd',pasword:'ada'},
    {id:57e6,name:'kejh',lastName:'dasdasd',password:'ada'},
    {id:57e6,name:'oiuyu',lastName:'dasdasd',password:'ada'}
]

for usuario in usuarios
     - var key = Object.keys( usuario )[1]
     - var val = usuario
     p #{key}: #{usuario.name}

// Probado en Codepen, creo que sigue usando Jade

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.