我正在创建一个管理面板,可以在使用alanning:roles
时通过选择控件来更改用户角色。我遇到的问题是我无法获得与每个选择控件关联的用户。我在使用Meteor创建管理面板时引用了this tutorial,但是当我调用changeRoles方法时,控制台会返回以下错误:
原始问题:已解决
Error: Missing 'users' param
I20190218-14:59:27.319(-6)? at Object._updateUserRoles (packages/alanning_roles.js:684:23)
I20190218-14:59:27.319(-6)? at Object.setUserRoles (packages/alanning_roles.js:250:11)
I20190218-14:59:27.320(-6)? at MethodInvocation.changeRole (server/main.js:88:13)`
更改了以下代码:
Template.userHome.events({
'click #confirmChanges': function (event) {
let currentRole = $(event.target).find('option:selected').val();
let userId = $(event.target.id).val();
console.log(userId);
if (window.confirm("Change User Roles?")) {
Meteor.call("changeRole", {
role: currentRole,
user: userId
})
window.location.reload();
}
}
})
对此(更改我设置userId值的方式):
Template.userHome.events({
'change [name="userRole"]': function (event) {
let currentRole = $(event.target).find('option:selected').val();
let userId = $(event.target.id);
console.log(currentRole);
if (window.confirm("Change User Roles?")) {
Meteor.call("changeRole", {
role: currentRole,
user: userId
})
window.location.reload();
}
}
})
现在,Roles.setUserRoles()无法正常工作,但参数具有值 console.log(options.role)返回正确的值和
console.log(options.user)返回:
I20190219-20:37:37.527(-6)? { length: 0,
I20190219-20:37:37.528(-6)? prevObject:
I20190219-20:37:37.529(-6)? { length: 0,
I20190219-20:37:37.529(-6)? prevObject:
I20190219-20:37:37.529(-6)? { length: 0,
I20190219-20:37:37.530(-6)? prevObject: [Object],
I20190219-20:37:37.530(-6)? context: [Object],
I20190219-20:37:37.531(-6)? selector: '3FzfDhZWcGFg6ggTE' },
I20190219-20:37:37.531(-6)? context: { location: [Object] } },
I20190219-20:37:37.532(-6)? context:
I20190219-20:37:37.532(-6)? { location:
I20190219-20:37:37.532(-6)? { href: 'http://localhost:3000/userHome',
I20190219-20:37:37.533(-6)? ancestorOrigins: {},
I20190219-20:37:37.533(-6)? origin: 'http://localhost:3000',
I20190219-20:37:37.534(-6)? protocol: 'http:',
I20190219-20:37:37.534(-6)? host: 'localhost:3000',
I20190219-20:37:37.534(-6)? hostname: 'localhost',
I20190219-20:37:37.534(-6)? port: '3000',
I20190219-20:37:37.535(-6)? pathname: '/userHome',
I20190219-20:37:37.535(-6)? search: '',
I20190219-20:37:37.536(-6)? hash: '' } } }
客户代码:
Template.userHome.events({
'change [name="userRole"]': function (event) {
let currentRole = $(event.target).find('option:selected').val();
let userId = $(event.target.id);
console.log(currentRole);
if (window.confirm("Change User Roles?")) {
Meteor.call("changeRole", {
role: currentRole,
user: userId
})
window.location.reload();
}
}
})
服务器代码:
Meteor.methods({
changeRole( options ) {
console.log("Change User is Being Called");
try {
Roles.setUserRoles( options.user, [ options.role ] );
console.log(options.role)
} catch( exception ) {
console.log(exception);
}
}
});
UserHome模板
<div class="nav">
<p class="welcomeUser">Welcome, {{#with userInfo}}{{profile.firstname}} {{profile.lastname}}{{/with}}</p>
<button id="logout" class="universalButton">Log Out</button>
</div>
<div class="pageContent">
{{#if userIsAdmin}}
<div class="adminPanel">
<table id="userTable">
<caption>Admin Panel</caption>
<tr>
<th class="usertableHead">Username</th>
<th class="usertableHead">Role</th>
</tr>
{{#each users}}
<tr>
<td class="usertableData">{{username}}</td>
<td class="usertableData">
<div class="styled-select purple rounded">
<select id={{_id}} name="userRole">
<option value={{roles}}>{{roles}}</option>
<option value="Teacher">Teacher</option>
</select>
</div>
</td>
</tr>
{{/each}}
</table>
<button id="confirmChanges" class="universalButton">Confirm Changes</button>
</div>
{{/if}}
</div>
答案 0 :(得分:0)
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
import re
# Initializing our dictionary
dictionary = {}
# Initializing our url key
url_key = 'url'
dictionary.setdefault(url_key, [])
# Initializing our text key
text_key = 'text'
dictionary.setdefault(text_key, [])
def text_scraper(page_soup):
text_body = ''
# Returns the text of p tags, we stopped it at -5 bc that's when the text is irrelevant to the article
for p in page_soup.find_all('p'):
text_body += p.text
return(text_body)
def article_scraper(url):
# Opening up the connection, grabbing the page
uClient = uReq(url)
page_html = uClient.read()
uClient.close()
# HTML parsing
page_soup = soup(page_html, "html.parser")
dictionary['url'].append(url)
dictionary['text'] = text_scraper(page_soup)
return dictionary
articles_zero = 'https://www.sfchronicle.com/news/bayarea/heatherknight/article/Special-education-teacher-a-prime-example-of-13560483.php'
article = article_scraper(articles_zero)
article
应该打印用户的console.log(options.user)
,而不是jQuery对象。在您的_id
事件中,将change [name="userRole"]
替换为let userId = $(event.target.id);
分配和检索值的更好方法如下:
HTML:
let userId = event.target.id;
JS:
...
<select data-id={{_id}} name="userRole">
<option value={{roles}}>{{roles}}</option>
<option value="Teacher">Teacher</option>
</select>
...