select下拉选项调用另一张数据库表数据
2016-01-31 10:25
459 查看
页面展示,一个下拉框,如下:
确定id ,通过id 调用ajax 方法,js源码如下:
function的初始化方法:
select下拉选项for循环遍历,根据id获得velue:
编辑页可用同种方法,but方法名不可以相同,id也不相同
更多有关jquery信息http://www.w3school.com.cn/jquery/
<tr> <td style="padding:8px;"><label for="pathTypeId">链路类型:</label></td> <td> <select name="pathTypeId.id" id="pathTypeId" style="width:140px;" > </select> </td> </tr>
确定id ,通过id 调用ajax 方法,js源码如下:
<script > $(function(){ // alert(123); initSelect(); }) function initSelect(){ $.ajax({ url:'${basePath}/admin/pathType/getAllData', type:'get', data:'json', success:function(res){ res=JSON.parse(res); //JSON转换为对象 for(var i=0;i<res.length;i++){ console.log(res[i]); $("#pathTypeId").append("<option value='"+ res[i].id +"'>"+ res[i].name +"</option>"); } }, error:function(){ alert("pathTypeId init fail"); } }); } </script>
function的初始化方法:
$(function(){ // alert(123); initSelect(); })url获取数据得到一个对象,controller层方法如下:
@RequestMapping(value = "getAllData") @ResponseBody public List<Path> findAll(){ List<Path> AllInfo = pathBiz.findAll(); return AllInfo; }
select下拉选项for循环遍历,根据id获得velue:
$("#pathTypeId").append("<option value='"+ res[i].id +"'>"+ res[i].name +"</option>");
编辑页可用同种方法,but方法名不可以相同,id也不相同
更多有关jquery信息http://www.w3school.com.cn/jquery/
相关文章推荐
- 数据仓库概述
- 啊啊啊啊啊啊啊今天就写,炒鸡简单 数据库Sqlite的创建,库的增删改查
- SQL Server 插入百万级数据
- 五种SQL Server分页存储过程的方法及性能比较
- hibernate链接数据库链接池c3p0配置
- hibernate链接数据库链接池c3p0配置
- hibernate链接数据库链接池c3p0配置
- Oracle表空间和表的区别
- springmvc整合mybatis框架源码 bootstrap html5 mysql oracle
- Oracle高级查询
- uniDBGrid导入数据库(转红鱼儿)
- Redis源码解析:05跳跃表
- Oracle单节点开启关闭归档日志
- redis Ok2
- redis OK
- Redis
- redis 链表操作
- postgresql使用
- mongodb 交互式操作和script文件脚本的区别。
- mysql笔记05 优化服务器设置