Grails 动态下拉列表为 edit.gsp 添加所选值
Grails dynamic dropdown add selected value for edit.gsp
我的 _form.gsp 上有一个动态下拉列表,该下拉列表在创建和编辑 gsp 中呈现。它工作正常,但我希望所选值显示在 edit.gsp 上。
_form.gsp
<g:select name="plant.id" id="plant" from="${MCM.MGPlant.list(sort:'member')}" value="${MGMatriceInstance?.plant?.id}" optionKey="id" noSelection="${[null: 'Select One...']}"
onchange='loadCostCenter(this.value);'/>
<g:select id="costCenter" name="costCenter.id" from="${[]}" optionKey="id" noSelection="${[null: 'Select One...']}"/>
<script type="text/javascript">
function loadCostCenter(init)
{
var root="${resource()}";
var plantid = document.getElementById('plant').value;
var url = root+'/MGMatrices/findCostCenterForPlant?plantId='+plantid;
jQuery('#costCenter').load(url);
}
</script>
在以下示例中,当单击 select 中的国家/地区时,它会显示 ajax 中国家/地区的位置。在国家/地区更换工厂,在位置更换成本。
在_temp1模板中,仅放置工厂和div(用于成本下拉列表)和一个文本框(用于存储来自编辑的成本ID)。
为成本创建另一个模板。这将在"动态"中选择工厂时显示成本。
在编辑操作中,您必须发送工厂实例和成本实例才能查看。
在 create.gsp 和 edit.gsp 中
...........
<script type="text/javascript">
jQuery(function() {
getSelectedCountry();
});
function getSelectedCountry(){
var selectedCountry = jQuery("#country").val();
var locationId = jQuery("#locationId").val();
alert(locationId)
if(selectedCountry != ''){
if(locationId!=''){
${remoteFunction (controller: 'country', action: 'locations', params: '''countryId='' + selectedCountry+''&locationId=''+locationId', update: 'updateLocation')}
}
else
${remoteFunction (controller: 'country', action: 'locations', params: '''countryId='' + selectedCountry', update: 'updateLocation')}
}
}
</script>
......
<g:render template="form" />
......
在 _form.gsp 中:
<g:select name="country" id="country" from="${com.ard.Country.list()}"
optionKey="id" noSelection="${['': 'Select']}" value="${countryInstance?.id}"
onchange='getSelectedCountry();'/>
<div id="updateLocation"></div>
<g:textField name="locationId" value="${locationInstance.id}"/>
在 _locations.GSP 中
<g:select id="location" name="location" from="${locations}" value="${locationInstance.id}"optionKey="id" noSelection="${[null: 'Select One...']}"/>
在控制器操作中,
def locations(){
def country = Country.get(params.countryId)
def locations = country.locations
def loc
if(params.locationId)
loc = Location.get(params.locationId)
render(template:"locations",model[locations:locations,locationInstance:loc])
}
在编辑操作中:
edit(){
......
render(view:"edit" ,model:[countryInstance:country,locationInstance:locationInstance]
}
相关文章:
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 如何在映射数组中添加换行符
- 正在将数据主题添加到所有项目
- ZeroClipboard-在复制之前添加到值
- 我可以在json对象中添加一个函数吗
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 正在SharePoint 2013母版页中添加JQuery移动文件
- 如何添加浮动和非浮动,其他
- 添加文字和评论功能更新Div
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 在函数中添加数组元素的数值
- 如何将歌曲添加到jPlayer
- 在html Select中添加搜索
- Java脚本时间添加
- FabricJs-限制主对象内添加对象的移动区域
- JQuery添加元素需要在我的js之前再次添加JQuery脚本
- 如何在Google柱状图中动态添加行/列
- 正在尝试使用if和else添加类,但无法正常工作
- Grails 动态下拉列表为 edit.gsp 添加所选值