问题描述
场景:
我有一个级联场景,其中第二个下拉列表中的值取决于第一个.我有布局"、输入"和内部"三个模板.
尝试:
我正在对输入"模板中第一个下拉列表的更改进行 ajax 调用,并坚持处理返回的响应.目前我找到了一种通过替换第二个下拉列表的 html 来修复它的方法.但是,我认为这不是更好的处理方式.我想要一些不需要修改 html 的渲染模板.
请帮助以更好的方式完成任务或指向一些维基.仅标准库
谢谢,
在更高级别上,您有 2 个选择:
onchange
详细说明 #2:从 AJAX 调用结果填充列表
您还有两种选择:
AJAX 返回 HTML
value;text
Scenario:
I have a cascade scenario, where values in second dropdown depends upon first. I have three templates "layout", "input" and "inner".
Attempt:
I'm making ajax call on change of first dropdown in "input" template and stuck with handling the response returned. Currently I found a way to fix it by replacing html of second dropdown. But, I think this is not the better way to handle. I want something in line of rendering templates where I do not need to amend html.
please help in acheiving the task in better way or point to some wiki. Only Standard Library
Thanks,
On the higher level you have 2 options:
onchange
Elaborating #2: populating list from the AJAX call result
You also have 2 options to do this:
AJAX returning HTML
{{define "innerList"}}
{{range .}}
<option value="{{.Key}}">{{.Text}}</option>
{{end}}
{{end}}
You can execute only this template like this:
// tmpl is the collection of your templates
values := ... // Load/construct the values
tmpl.ExecuteTemplate(w, "innerList", values)
values
type Pair struct {
Key string
Text string
}
value;text
var x = document.getElementById("mySelect");
var option = document.createElement("option");
option.value = "1234";
option.text = "Kiwi";
x.add(option);
这篇关于如何使用 golang&#39;s 模板实现级联下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!