フォローアップ:文字列引数を持つMeteor.Users
-
21-12-2019 - |
質問
私はユーザー_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 ColleaGue= Meteor.Users.Findone({_ ID:self})を実行するときにエラーを投げます。具体的には、オブジェクト0にメソッド 'SUPSTR'
がないタイプエラーをスローします。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がCulpritである可能性があることがわかります。
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をrと描くとき(JavaScriptデバッガのローカル変数モニタで確認されています):
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(オブジェクト)の値を返します。
私はこれが私の問題の根本的な原因です。これは流星のバグですか?誰もがこの問題を回避する方法を知っていますか?
事前に助けてくれてありがとう。
解決
OK、文字列を明示的に入力して文字列を入力して動作します。とても奇妙な。
if (self) {
var colleague=Meteor.users.findOne({_id:String(self)});
console.log(colleague);
if (colleague.username)
. 所属していません StackOverflow