【发布时间】:2014-07-15 19:04:06
【问题描述】:
我有一个自定义模板标记,它通过对 SOAP 服务的 Web 调用检索国家列表并填充 html select 标记。现在我有了另一个模板标签,它显示给定国家/地区的选项列表,很明显,它将国家名称作为参数。因此,只有在 onchange 事件在 html 选择标签上触发并且我将国家名称作为用户选择的 javascript 变量后,我才能将国家名称传递给第二个自定义标签。我如何将此值传递给自定义模板标签? 这是我的自定义标签
from mezzanine import template
from suds.client import Client
register = template.Library()
@register.as_tag
def get_countries(*args):
url = 'http://www.sendfromchina.com/shipfee/web_service?wsdl'
client = Client(url)
countries = client.service.getCountries()
countries = map(lambda x: x._enName, countries)
return countries
@register.as_tag
def get_available_carriers(weight,country,length,width,height):
url = 'http://www.sendfromchina.com/shipfee/web_service?wsdl'
client = Client(url)
rates = client.service.getRates(weight,country,length,width,height)
rates=map(lambda x: (x._shiptypecode, x._totalfee), rates)
return rates
这是我的html 选择标签
<select id='countrylist' onchange="getOption(this)">
{% get_countries as countries %}
{% for country in countries %}
<option>{{ country }}</option>
{% endfor %}
<select>
最后,这是我的 javascript
<script type="text/javascript">
function getOption(sel){
var country = sel.value;
{% get_available_carriers 1 country 10 10 10 as carriers %}
console.log('{{ carriers }}')
}
</script>
我似乎无法将 country js 变量传递给 get_available_carriers 标记
非常感谢任何帮助!谢谢
【问题讨论】:
标签: javascript jquery django django-templates