【问题标题】:Struts 2 <s:doubleselect> Tag Uncaught TypeError: Cannot read property 'applicant_jobTitle' of undefined [closed]Struts 2 <s:doubleselect> Tag Uncaught TypeError: Cannot read property 'applicant_jobTitle' of undefined [关闭]
【发布时间】:2014-01-13 14:05:41
【问题描述】:

我有两个下拉列表的动态填充列表。 第一个下拉列表让您选择工作区域列表,而第二个下拉列表将根据第一个下拉列表的选定选项动态填充。如果我使用这个标签来保存数据一切都很好,但如果我用它来编辑现有数据,第二个下拉菜单永远不会删除选项。我认为当 struts 2 想要为 第二个下拉列表 赋予价值时会出现问题。我在 web 控制台下发现了这个错误。

未捕获的 TypeError:无法读取未定义的属性 'applicant_jobTitle'

这是我的jsp

<s:doubleselect label="Job Applied"  required="true" 
 headerKey="-1"   headerValue="Select Job Area" 
       name="applicant.jobArea"          list="listJobArea.keySet()      
 doubleName="applicant.jobTitle"   doubleList="listJobArea.get(top)"     
 formName="formApplicant"/> 

这是我的html

<form action="updateApplicant" class="class java.util.HashMap" enctype="multipart/form-data" method="post">

<p>
<s:hidden cssClass="textfield" name="applicant.applicantNo" />
<s:hidden cssClass="textfield" name="applicant.dateAdded" />
<s:hidden cssClass="textfield" name="applicant.status" />
</p>
<p>
<s:textfield cssClass="textfield" name="applicant.firstName" required= "true"
    label="Firstname" />
</p>
<p>
<s:textfield cssClass="textfield" name="applicant.lastName" required= "true"
    label="Lastname" />
</p>
<br>
<p>
<s:textfield cssClass="textfield" required= "true" name="applicant.email" label="Email" />
</p>
<br>
<p>
<s:textfield cssClass="textfield" name="applicant.contactNo" required= "true"
    label="Contact Number" />
</p>
<br>
<s:doubleselect label="Job Applied"  required="true" 
        headerKey="-1"   headerValue="Select Job Area" 
          name="applicant.jobArea"          list="listJobArea.keySet()      
         doubleName="applicant.jobTitle"   doubleList="listJobArea.get(top)"     
        formName="formApplicant"/> 

    <input type="submit" id="submit" name="action:cancel" value="Cancel" >    
    <input value="Update" type="submit" name="submit" /> 

这是从 doubleselect struts 2 标签自动生成的 javasript

错误将显示在一行中 --> applicant_jobAreaRedirect(1);

<script type="text/javascript">
var applicant_jobAreaGroup = new Array(2 + 1);
for (i = 0; i < (2 + 1); i++)
applicant_jobAreaGroup[i] = new Array();

applicant_jobAreaGroup[1][0] = new Option("Select Job Title", "Select Job Title");

applicant_jobAreaGroup[1][1] = new Option("Application Architect", "Application Architect");

applicant_jobAreaGroup[1][2] = new Option("Business Architect", "Business Architect");

applicant_jobAreaGroup[2][0] = new Option("Select Job Title", "Select Job Title");

applicant_jobAreaGroup[2][1] = new Option("Application Consultant", "Application Consultant");

applicant_jobAreaGroup[2][2] = new Option("Engagement Manager", "Engagement Manager");

applicant_jobAreaGroup[2][3] = new Option("General Other Consultant", "General Other Consultant");


var applicant_jobAreaTemp = document.formApplicant.applicant_jobTitle;
applicant_jobAreaRedirect(1);
function applicant_jobAreaRedirect(x) {
    var selected = false;
    for (m = applicant_jobAreaTemp.options.length - 1; m >= 0; m--) {
        applicant_jobAreaTemp.options[m] = null;
    }

    for (i = 0; i < applicant_jobAreaGroup[x].length; i++) {
        applicant_jobAreaTemp.options[i] = new Option(applicant_jobAreaGroup[x][i].text, applicant_jobAreaGroup[x][i].value);
            if (applicant_jobAreaTemp.options[i].value == 'Application Architect') {
                applicant_jobAreaTemp.options[i].selected = true;
                selected = true;
            }
    }

    if ((applicant_jobAreaTemp.options.length > 0) && (! selected)) {
        applicant_jobAreaTemp.options[0].selected = true;
    }
}

我的双选标记或编辑此 javascript 的方法有问题吗? 或者如何编辑或获取double.ftl

【问题讨论】:

  • 能贴出相关的HTML代码吗?
  • 好的,我会添加html代码@RomanC​​pan>

标签: java javascript jsp struts2


【解决方案1】:

我刚刚在我的 jsp 上添加了我的表单名称..看起来我忘了放它。

【讨论】:

    猜你喜欢
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 2021-03-16
    • 2017-02-18
    • 2019-02-12
    • 2021-09-20
    • 2021-06-08
    相关资源
    最近更新 更多