Hi, everyone.I'm a beginner at Meteor.
After meter remove secure, I'm stuck with how to get {{#IF}} to recognize the results of the server decision.
[What I want to do]
Instead of using {{#each}} to subscribe to the cursor in the database,
I want to use {{#IF}} to show the appropriate text only to the person who logged in with the administrator's email address, but I don't know how to do it.
[Symptoms]
As for the code described below, the part where the server checks if it is an administrator is able to determine true/false.However, the results are not returned to the client side and are undefined.
調べてWhat I thought after researching 考えた
http://docs.meteor.com/#/full/meter_call
contains OnOn the client, if you do not pass a callback and you are not inside a stub, call will return undefined, .. とある, which exactly matches the symptom.So if I write in callback,
1. As it is asynchronous, if the timing of the decision is late, it may not be reflected in {{#IF}}?
2. I don't know how to return the result of true/false determined by the callback function to the original {{#IF}}.
There is a problem thatAt worst, I think I should save 2 in a global variable or database...
I think these cases are common, but do you know any smart way to do this?
[Code]
-client.html-ooh-ooh-ooh-ooh-ooh-ooh-ooh-ooh-ooh-ooh-ooh-ooh-ooh-ooh!
<template name="showToAdmin">
{{#if showToAdminText}}
appropriate text
{{/if}}
</template>
- client.js - client.js - client.js - client.js - client.js - client.js - client.js _yomi
Template.showToAdmin.helpers({
'showToAdminText': function() {
return Meteor.call('showToAdminText');
}
});
- server.js - server.js - server.
Meteor.methods({
'showToAdminText': function() {
varcurrentUserId = this.userId;
if(currentUserId){
varaddress =Meter.users.findOne(currentUserId).emails[0].address;
return(address=='[email protected]');
}
return false;
}
});
I thought about one way and actually worked.
You can create a collection like IsAdminLoggingIn, which can be subscribed from the server side (not subscribed to other user IDs) when the administrator ID is logged in, and the client determines undefined/true to retrieve the value from the collection.
This is OK for the time being, but it's a little exaggerated, so if you know any smarter way, I'd appreciate it if you could give me a suggestion.
© 2024 OneMinuteCode. All rights reserved.