选择足球队和输出足球队的位置 [英] Select Soccer Team and Output Soccer Team's Location

查看:143
本文介绍了选择足球队和输出足球队的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个表单,在那里有人选择一个团队,然后团队的位置应该输出一个div。



这是我到目前为止。

 < select id =如何从正确的团队获取位置? chooseTeamname =chooseTeamdata-placeholder =选择团队> 
< option>< / option>
{团队中的团队%}
< option> {{team.name}}< / option>
{%endfor%}
< / select>

< div> {{team.location}}< / div>







  class Team(db.Model):
__tablename__ ='Team'
id = db.Column(db.Integer,primary_key = True)
name = db.Column(db.String())
location = db.Column(db.String())


解决方案

基本上,您必须编写一个JavaScript函数来检查用户是否选择了特定的团队。如果选择了一个,则向服务器发出一个AJAX请求,包括所选的 {{team.name}} 值。在服务器上,编写一个函数,在该函数中检查数据库中的哪个 Team 实例具有所选的名称。一旦找到它,您可以查询该特定团队的位置,并将其作为HTTP或XML格式的HTTP响应返回。在 $。ajax()函数的成功处理程序中,您可以使用jQuery选择器来检索位置并将其添加到您的DIV。


I am creating a form, where someone chooses a team and then the team's location should be outputted in a div.

Here is what I have so far. How do I get the location from the correct team - the one that is chosen by the user?

<select id="chooseTeam" name="chooseTeam" data-placeholder="Select Team">
    <option></option>
    {% for team in teams %}
        <option>{{team.name}}</option>
    {% endfor %}
</select>

<div>{{team.location}}</div>

class Team(db.Model):
    __tablename__ = 'Team'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String())
    location = db.Column(db.String())

解决方案

Basically, you have to write a JavaScript function that checks whether a specific team has been selected by the user. If one has been selected, you make an AJAX request to the server including the chosen value of {{team.name}}. On the server, write a function in which you check which Team instance in your database has that selected name. As soon as you have found it, you can query the location of that particular team and return it as an HTTP response in XML or JSON format. In the success handler of your $.ajax() function, you can retrieve the location and add it to your DIV using jQuery selectors.

这篇关于选择足球队和输出足球队的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆