문제

사용자 _id 문자열을 통해 템플릿 반복을 가져옵니다.

    <div class="page-header"><h4>Colleagues</h4></div>
        <ul class="list-group">
            {{#each colleague}}
                <li class="list-group-item">
                    <div class="colleague">
                    {{nameOrEmail}}
                    </div>
                </li>
            {{/each}}
        </ul>
.

전화 할 때

nameOrEmail: function () {
    if (myTeam.ready()) {
        console.log ("into function nameorEmail");
        console.log(this);
        var self=this;
        if (self) { 
        var colleague=Meteor.users.findOne({_id:self});
        console.log(colleague);
        if (colleague.username)
            return colleague.username;
        else if (colleague.emails.count()>0)
            return collegue.emails[0].address;
        }}
    return null;
.

템플릿 내에서 var Colleauge= meteor.users.findone ({_ id : self})을 실행할 때 오류가 tosk입니다. 특히 객체 0이 메소드 'substr'

가없는 유형 오류를 던집니다.
manageAccount.js?a86dcce62b84091cf50c653de6d2db7f0102a155:59
Exception from Deps recompute function: TypeError: Object 0 has no method 'substr'
at http://localhost:3000/packages    /minimongo.js?4ee0ab879b747ffce53b84d2eb80d456d2dcca6d:1211:33
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:159:22)
at isOperatorObject (http://localhost:3000/packages/minimongo.js?4ee0ab879b747ffce53b84d2eb80d456d2dcca6d:1210:5)
at compileValueSelector (http://localhost:3000/packages/minimongo.js?4ee0ab879b747ffce53b84d2eb80d456d2dcca6d:1406:14)
at http://localhost:3000/packages/minimongo.js?4ee0ab879b747ffce53b84d2eb80d456d2dcca6d:1386:9
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:164:22)
at compileDocumentSelector (http://localhost:3000/packages/minimongo.js?4ee0ab879b747ffce53b84d2eb80d456d2dcca6d:1369:5)
at _.extend._compileSelector (http://localhost:3000/packages/minimongo.js?4ee0ab879b747ffce53b84d2eb80d456d2dcca6d:1346:12)
at new Minimongo.Matcher (http://localhost:3000/packages/minimongo.js?4ee0ab879b747ffce53b84d2eb80d456d2dcca6d:1289:27)
at new LocalCollection.Cursor (http://localhost:3000/packages/minimongo.js?4ee0ab879b747ffce53b84d2eb80d456d2dcca6d:142:20) 
.

JavaScript 콘솔에서 FindOne 명령을 실행하고 예상 결과를 얻을 수 있음을 확인했습니다. 또한 Meteor 기능을 통해 프로그램의 실행을 추적했습니다. selector.js 파일의 함수 _.type이 범인 일 수 있다는 것으로 나타납니다.

LocalCollection._f = {
// XXX for _all and _in, consider building 'inquery' at compile time..

_type: function (v) {
if (typeof v === "number")
  return 1;
if (typeof v === "string")
  return 2;
if (typeof v === "boolean")
  return 8;
if (isArray(v))
  return 4;
if (v === null)
  return 10;
if (v instanceof RegExp)
  // note that typeof(/x/) === "object"
  return 11;
if (typeof v === "function")
  return 13;
if (v instanceof Date)
  return 9;
if (EJSON.isBinary(v))
  return 5;
if (v instanceof LocalCollection._ObjectID)
  return 7;
return 3; // object
.

v를 v로 추적 할 때 (자바 스크립트 디버거 로컬 변수 모니터에서 확인) :

String {0: "d", 1: "e", 2: "P", 3: "k", 4: "j", 5: "N", 6: "j", 7: "4", 8: "8", 9: "T", 10: "e", 11: "F", 12: "v", 13: "d", 14: "z", 15: "v", 16: "K", length: 17} 
.

2 (문자열)가 아닌 3 (객체) 값을 반환합니다.

나는 이것이 내 문제의 근본 원인이라고 생각한다. 이게 유성의 벌레입니까? 이 문제를 해결하는 방법을 알고 있습니까?

어떤 도움에도 미리 감사드립니다.

도움이 되었습니까?

해결책

확인, 문자열을 입력하여 문자열을 명시 적으로 캐스팅하고 이제는 작동합니다.매우 이상합니다.

        if (self) { 
        var colleague=Meteor.users.findOne({_id:String(self)});
        console.log(colleague);
        if (colleague.username)
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top