Hello Guys我使用bootstrap-typeahead.js来获取我的flask项目中所有用户列表的json数据。
根据Bootstrap Type的基本行为,我可以在类型提前调用函数下查看指定的json数据,但无法获取如何获取json数据。
此代码段将采用城市的JSON列表,然后使用typeahead
显示<p>Type Query: <input type="text" class="input-medium search-query" id="cities" data-provide="typeahead" data-items="4" ></input></p>
<script type="text/javascript"></script>
$('#cities').typeahead({
source: [
{ id: 1, name: 'Toronto' },
{ id: 2, name: 'Montreal' },
{ id: 3, name: 'New York' },
{ id: 4, name: 'Buffalo' },
{ id: 5, name: 'Boston' },
{ id: 6, name: 'Columbus' },
{ id: 7, name: 'Dallas' },
{ id: 8, name: 'Vancouver' },
{ id: 9, name: 'Seattle' },
{ id: 10, name: 'Los Angeles' }
]
});
但是当我想从远程源或文件中获取数据时应该是这样的twitter-bootstrap-typeahead
$('#cities').typeahead({
ajax: '/sample/list'
});
但这不符合我的要求。
我有这个视图来获取Python Flask中的所有用户
@app.route('/users')
@login_required
def get_all_users():
all_users = model.User.query()
first = {}; users = []
for user in all_users:
user_key = user.key
first['uname'] = user.name
first['uuid'] = user_key.integer_id()
first['about_me'] = user.about_me
first['email'] = user.email
users.append(first)
first = {}
return jsonify(users=users)
它会抛出类似这样的数据
{
"users": [
{
"about_me": null,
"email": "chitrankdixit@gmail.com",
"uname": "Chitrank",
"uuid": 5066549580791808
},
{
"about_me": null,
"email": "test@example.com",
"uname": "Test",
"uuid": 5629499534213120
}
]
}
现在我完全感到困惑,为什么typeahead没有从我的烧瓶视图中获取JSON数据。请帮忙