afQuickFie-6ren">
gpt4 book ai didi

javascript - Meteor afFormGroup 未填充下拉框

转载 作者:行者123 更新时间:2023-12-03 10:01:06 28 4
gpt4 key购买 nike

html如下:

<template name="addUser">
{{#autoForm id="addUser" schema=schema meteormethod="newUser"}}
<fieldset>
{{> afQuickField name="fName"}}
{{> afQuickField name="lName"}}
{{> afQuickField name="username"}}
{{> afQuickField name="email"}}
{{> afFormGroup name="roles" firstoption="Select Role" options=addUseroptions type="select"}}
{{> afQuickField name="password"}}
<div>
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</fieldset>
{{/autoForm}}
</template>

afFormGroup Angular 色未填充。我试图用当前存储在 mongodb 中的所有 Angular 色填充下拉框,但下拉列表仍然为空。正确的值显示在 console.log() 语句的控制台中。

js如下:

Template.addUser.helpers({
schema : function (){
return MySchema.addUser;
},
collection : function (){
return MyCollections.Users;
},
addUseroptions: function (){
var array = [];
var array2 = [];
roles = Roles.getAllRoles();
array = roles.fetch();

for(var i = 0; i < roles.count(); i++){
array2[i] = array[i].name;
}
console.log(roles.count());
console.log(array2);

return
[{
optgroup: "Roles",
options: array2
}];
}
});

最佳答案

你的帮助功能似乎有点困惑。试试这个:

// Still inside your "helper" block
addUseroptions: function() {
return Roles.getAllRoles().map(function(r) {
// "r" here is a single document returned by the cursor. Use this
// space to do whatever change you wanna do in respect to
// label name or select value
return {label: r.name, value: r.name};
});
}

关于javascript - Meteor afFormGroup 未填充下拉框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30595912/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com