Я использую Select2 AUTOFORM и у меня есть следующая схема:Как получить доступ к собственному идентификатору пользователя в AutoForm Select2 Meteor?
Schema = {};
Schema.users = new SimpleSchema({
users: {
type: [String],
autoform: {
type: "select2",
options: function() {
return Users.find().map(function (user) {
return {label: user.username, value: user._id};
});
}
}
}
});
Теперь это работает фантастически, но проблема в том, что в настоящее время вошли в систему пользователя, также перечислены в качестве опции. Я хочу, чтобы удалить эту Particulary вариант, поэтому я попытался следующие:
Schema = {};
Schema.users = new SimpleSchema({
users: {
type: [String],
autoform: {
type: "select2",
options: function() {
var userId = this.userId;
return Users.find().map(function (user) {
if(user._id != userId) return {label: user.username, value: user._id};
});
}
}
}
});
Однако this.userId
не доступен. Как я могу получить доступ к этой переменной?
EDIT: Я попытался установить варианты на стороне клиента, но это не сработало:
Template.users.helpers({
userFormSchema: function() {
return Schema.users;
},
usersOptions: function() {
return Users.find().map(function (user) {
if (Meteor.userId() != user._id) return {label: user.username, value: user._id};
});
}
});
<template name="users">
<div class="page-content">
{{#autoForm schema=userFormSchema id="insertUserForm" type="method" meteormethod="userInsert"}}
{{> afFieldInput name="users" type="select2" multiple=true options=usersOptions}}
<button type="submit" class="btn btn-primary">Submit</button>
{{/autoForm}}
</div>
</template>
Я получил следующие исключения:
[Log] Exception in template helper: http://localhost:3000/packages/aldeed_autoform-select2.js?24d34b2898684fa0e8487085f4278d6dbda6a9c4:153:14 (meteor.js, line 880)
[email protected][native code]
[email protected]://localhost:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:149:18
[email protected]://localhost:3000/packages/aldeed_autoform-select2.js?24d34b2898684fa0e8487085f4278d6dbda6a9c4:152:11
[email protected]://localhost:3000/packages/aldeed_autoform.js?8d8955f3aabfe2ab46c89e06e9d94100df40ae6d:7107:91
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2986:21
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1650:21
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3038:71
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3671:16
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3037:52
[email protected]://localhost:3000/packages/spacebars.js?1aedcc2aa3ae9ff5d860d73516110cedd77c033e:167:23
http://localhost:3000/packages/aldeed_autoform.js?8d8955f3aabfe2ab46c89e06e9d94100df40ae6d:7000:27
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2900:21
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2613:30
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1872:24
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3671:16
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1870:54
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2211:16
with:[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1869:34
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:349:36
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:237:18
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:588:34
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1882:29
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2612:19
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1952:30
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:615:13
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1949:24
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2211:16
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1948:25
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1966:23
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2011:20
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1473:31
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1415:22
[native code]
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1424:11
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2030:53
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:615:13
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2028:28
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1872:24
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3671:16
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1870:54
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2211:16
DynamicTemplate:[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1869:34
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:349:36
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:368:22
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:507:24
[email protected]://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:365:23
[Log] Exception from Tracker afterFlush function: (meteor.js, line 880)
[Log] TypeError: undefined is not an object (evaluating 'template.data.atts') (meteor.js, line 880)
[Log] [email protected]://localhost:3000/packages/aldeed_autoform-select2.js?24d34b2898684fa0e8487085f4278d6dbda6a9c4:218:27 (meteor.js, line 880)
[email protected]://localhost:3000/packages/aldeed_template-extension.js?198fda9390ae7785a7535751677cd8247508c9eb:417:15
[email protected]://localhost:3000/packages/aldeed_template-extension.js?198fda9390ae7785a7535751677cd8247508c9eb:366:21
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3330:26
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3671:16
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3326:37
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3419:18
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1780:18
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2211:16
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1779:31
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:523:15
[email protected]://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:365:23
[Log] Exception in template helper: http://localhost:3000/packages/aldeed_autoform-select2.js?24d34b2898684fa0e8487085f4278d6dbda6a9c4:153:14 (meteor.js, line 880)
[email protected][native code]
[email protected]://localhost:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:149:18
[email protected]://localhost:3000/packages/aldeed_autoform-select2.js?24d34b2898684fa0e8487085f4278d6dbda6a9c4:152:11
[email protected]://localhost:3000/packages/aldeed_autoform.js?8d8955f3aabfe2ab46c89e06e9d94100df40ae6d:7107:91
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2986:21
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1650:21
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3038:71
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3671:16
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3037:52
[email protected]://localhost:3000/packages/spacebars.js?1aedcc2aa3ae9ff5d860d73516110cedd77c033e:167:23
http://localhost:3000/packages/aldeed_autoform.js?8d8955f3aabfe2ab46c89e06e9d94100df40ae6d:7000:27
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2900:21
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2613:30
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1872:24
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3671:16
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1870:54
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2211:16
with:[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1869:34
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:349:36
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:237:18
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:588:34
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1882:29
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2612:19
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1952:30
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:615:13
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1949:24
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2211:16
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1948:25
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1966:23
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2011:20
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1473:31
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1415:22
[native code]
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1424:11
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2030:53
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:615:13
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2028:28
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1872:24
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3671:16
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1870:54
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2211:16
DynamicTemplate:[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1869:34
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:349:36
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:368:22
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:507:24
[email protected]://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:365:23
[Log] Exception from Tracker afterFlush function: (meteor.js, line 880)
[Log] TypeError: undefined is not an object (evaluating 'template.data.atts') (meteor.js, line 880)
[Log] [email protected]://localhost:3000/packages/aldeed_autoform-select2.js?24d34b2898684fa0e8487085f4278d6dbda6a9c4:218:27 (meteor.js, line 880)
[email protected]://localhost:3000/packages/aldeed_template-extension.js?198fda9390ae7785a7535751677cd8247508c9eb:417:15
[email protected]://localhost:3000/packages/aldeed_template-extension.js?198fda9390ae7785a7535751677cd8247508c9eb:366:21
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3330:26
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3671:16
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3326:37
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:3419:18
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1780:18
[email protected]://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2211:16
http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:1779:31
[email protected]://localhost:3000/packages/tracker.js?7776276660c988c38fed448d8262b925dffb5bc3:523:15
[email protected]://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:365:23
С AutoForm вы можете задать параметры для выбор2 внутри шаблона или в схеме. Если вы укажете их в шаблоне, вы получите 'Meteor.userId()' available – challett