symfony - 填充多个下拉选择列表(AJAX) - 已更新
我有一个表单,有两个字段,即选择列表。
我需要从 select_list_1 中选择一个选项,然后填充 select_list_2
我的模板中有以下内容:
<script type="text/javascript">
$(document).ready(function() {
$('select#sf_guard_user_profile_corp_id').change(function() {
$.ajax({
url: "updateAreaManager?corp_id=" + this.value,
dataType: "text/html",
success: (function(data) {
$('select#sf_guard_user_profile_area_manager_id').html(data);
})
});
});
});
</script>
这会调用 executeUpdateAreaManager
方法,目前很简单:
public function executeUpdateAreaManager(sfWebRequest $request)
{
$id = $request->getParameter('corp_id');
}
有人能够帮助我获取我需要的数据吗进入第二个选择列表?
谢谢
I have a form, with 2 fields, that are select lists.
I need to select an option from select_list_1 that then populates select_list_2
I have the following in my template:
<script type="text/javascript">
$(document).ready(function() {
$('select#sf_guard_user_profile_corp_id').change(function() {
$.ajax({
url: "updateAreaManager?corp_id=" + this.value,
dataType: "text/html",
success: (function(data) {
$('select#sf_guard_user_profile_area_manager_id').html(data);
})
});
});
});
</script>
This calls the executeUpdateAreaManager
method, which currently is simply:
public function executeUpdateAreaManager(sfWebRequest $request)
{
$id = $request->getParameter('corp_id');
}
Would someone be able to help me get the data I need into the second select list?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测,由于您有一个 corp_id 传递给您的操作,因此您正在尝试根据 corp_id 值获取经理列表。
在您的操作中,您可以查询数据库以获得结果集,方法如下:
然后您可以将结果传递给您的 javascript,无论您想要什么方式。此时我建议直接使用 HTML。您的代码将类似于以下内容(仍在您的 action.class.php 文件中):
此时,您的 javascript 应该在页面上显示该 HTML。让它生成您需要的内容,假设您的情况是 HTML 表单。
I am guessing that since you have a corp_id being passed to your action, you are trying to get a list of Managers based on a corp_id value.
In your action, you can query your database in order to get a result set, by doing something like:
You then can pass the results to your javascript, whatever way you want. I suggest straight HTML at this point. Your code will ressemble something like this (still in your action.class.php file):
At this point, your javascript should be displaying that HTML on your page. Make it generate what you n eed, assuming an HTML form in your case.