FormAlchemy 下拉列表未设置值
我想做的就是使用使用Formalchemy 1.3.5 的字典来设置下拉列表的值。
文档内容如下:
采用选项参数的方法将接受多种指定这些选项的方法:
- SQLAlchemy 对象的可迭代对象;每个对象的str()将是描述,主键是值
- SQLAlchemy 查询;查询将使用 all() 执行,返回的对象按上述方式计算
- (描述、值)对的可迭代
- {description: value} 对的字典
我创建一个字典,如下所述:
Location = model.meta.Session.query(model.Location)
cityCodes = {}
for row in Location:
cityCodes.update({row.city : str(row.location_code)})
并包含它:
EmpsPerson.wiw_location_code.label('Location').dropdown(options = cityCodes),
但是,值仍然被设置为描述:
<option value="Dubai">Dubai</option>
<option value="Portsmouth">Portsmouth</option>
<option value="Toulouse">Toulouse</option>
<option value="Singapore">Singapore</option>
已解决:
所以为了解决这个问题,我刚刚使用了:
for row in Location:
cityCodes.append([row.city,int(row.location_code)])
EmpsPerson.location_code.label('Location').dropdown(options=cityCodes)
All Im trying to do is set the values of a drop down list using a dictionary using formalchemy 1.3.5.
The documentation reads:
Methods taking an options parameter will accept several ways of specifying those options:
- an iterable of SQLAlchemy objects; str() of each object will be the description, and the primary key the value
- a SQLAlchemy query; the query will be executed with all() and the objects returned evaluated as above
- an iterable of (description, value) pairs
- a dictionary of {description: value} pairs
I create a dictionary as is described here:
Location = model.meta.Session.query(model.Location)
cityCodes = {}
for row in Location:
cityCodes.update({row.city : str(row.location_code)})
and include it:
EmpsPerson.wiw_location_code.label('Location').dropdown(options = cityCodes),
However, the values are still being set as the description:
<option value="Dubai">Dubai</option>
<option value="Portsmouth">Portsmouth</option>
<option value="Toulouse">Toulouse</option>
<option value="Singapore">Singapore</option>
Solved:
So to fix this issue I just used:
for row in Location:
cityCodes.append([row.city,int(row.location_code)])
EmpsPerson.location_code.label('Location').dropdown(options=cityCodes)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜该文档已经过时了。尝试使用列表
I guess the doc is out of date. Try with a list