后台命名查询sql查某几个字段传到前台
dwr调用查出数据库字段 传给前台显示
前台只能接受list 后台数据放进list传入前台
name-quary中
<!-- 定义sql 通过单位id 查单位名称 -->
<sql-query name="getStationName">
<![CDATA[
select STATION_ID,STATION_NAME from MF_STATION where STATION_ID =:stationId or PARENT_STATION_ID=:stationId
]]>
<return-scalar column="station_id" type="string"/>
<return-scalar column="station_name" type="string"/>
</sql-query>
manager中
public List getName(Map<String, String> map) {
List list2 = new ArrayList();
String id = map.get("stationId");
if (id != null) {
List list = this.getDao().retrieveByNamedQuery("getStationName", "stationId", id); if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
Map<String, String> map1 = new HashMap<String, String>();
String stationId = (String) (((Object[]) list.get(i))[0]);
String stationName = (String) (((Object[]) list.get(i))[1]);
map1.put("stationId", stationId);
map1.put("stationName", stationName);
list2.add(map1);
}
}
}
return list2;
}
}
前端
/** * 生成下拉菜单 */
function getXL() {
var name;
gf_dwrInvoke("kwOpGroupInfoManager","getName",{"stationId":stationId},function(result){
if(result!=undefined && result != null){
for(i = 0;i < result.length ;i++){
if(result[i]!=undefined && result[i] != ""){
var o = document.createElement("option");
o.value = result[i].stationId;
o.text = result[i].stationName;
$get("stationId").options.add(o);
} } } });
// 删除重复选项
deleteReOption;
}