如果在使用一个以前未使用的标签的时候,如果用起来有什么功能不知道用它的哪些属性实现,最好能查一下这个标签的tld文件。我今天就碰到这样一个问题,在使用ajaxTags的select标签(解决两个下拉列表框的联动问题)时 ,需要实现这样一个功能:页面初始化的时候,第二个下拉框就要根据第一个下拉框初始化的值显示相应的级联效果。由于不知道怎么运用select标签的哪些属性,只好在页面显示前专门在后台写一个方法,返回第二个下拉列表框需要显示的值,然后在页面上用循环显示出来。(这方法够白痴的)后来有一较牛同事研究了一个多小时,给出了一个简单的方法,加入如下代码,问题解决。
<script type="text/javascript">
$("company").fireEvent('onChange');
</script>

解释一下这些代码,如果没人看,也算自己的备忘录了,嘿
这句代码要做的事就是:在页面初始化的时候company(也就是第一个下拉列表框)这个下拉列表框的值如果改变,也能触发onchange事件,从而能有效运用ajax的select标签的级联功能。
其中,$("company")等同于document.getElementById("company")。company即第一个下拉列表框的id。不过用这种方式得到company这个对象必须在页面引入prototype-1.4.0.js。如:<script type="text/javascript" src="js/ajaxtags/prototype-1.4.0.js"></script>
但是后来看ajaxtags的tld时,感觉傻了,tld内容如下:
<attribute>
<name>executeOnLoad</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>
Indicates whether the target select/dropdown should be populated when the object is
initialized (this is essentially when the form loads) [default=false]
</description>
</attribute>
<attribute>
<name>defaultOptions</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>
A comma-seperated list of values of options to be marked as selected by default if they
exist in the new set of options
</description>
</attribute>

最后的实现方法:
<ajax:select
baseUrl="showSelectPlace.do"
source="company"
target="place"
parameters="company={company}"
executeOnLoad="true"
defaultOptions="${MeetRoomManagerForm.mmsMeetingRoomInfo.mmsCodeTableByPlace.id}"
parser="new ResponseXmlParser()"/>
18万+

被折叠的 条评论
为什么被折叠?



