我有一个comboxbox,其值直接来自后端视图。后端视图由一个排序列组成,该列由2个字段创建,带有“|”中间的字符(field1 +“|”+ field2)。在组合框中创建值的公式是
var dbName = session.getCurrentDatabase();
var view = ("UniNames&Abbr");
var UniList = @Unique(@DbColumn(dbName,view,1));
return UniList
从此公式创建的列表中选择值时,view.postscipt警报会中断。没有别人打破。错误消息是:
执行JavaScript动作表达式时出错 脚本解释器错误,line = 9,col = 14:[TypeError]在类型为'String [JavaScript Object]'的对象上调用方法'postScript(string)'时出错
JavaScript代码 1://sessionScope.SavUniAbbr = sessionScope.UniAbbr; 2:var ComboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent(“ComboBox1”)。getValue(); 3:if(!! ComboBox1){ 4:print(“ComboBox1 =”,ComboBox1); 5:var type = typeof ComboBox1; 6:打印(“ComboBox1是类型”,类型) 7:var varAlert = ComboBox1 +“是type”+ type +“。”; 8:var al =“alert('”+ varAlert +“')”; 9:view.postScript(al); 10:var varAlert =“你选择了”+ ComboBox1 +“。”; 11:var al =“alert('”+ varAlert +“')”; 12:view.postScript(al); 13:}
这是我的代码:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex"
xmlns:xc="http://www.ibm.com/xsp/custom"
xmlns:bz="http://www.ibm.com/xsp/bazaar">
<xp:this.resources>
<xp:styleSheet href="/buttonptr.css"></xp:styleSheet>
<xp:script src="/SSJS.jss" clientSide="false"></xp:script>
<xp:styleSheet href="/CoopTeacher.css"></xp:styleSheet>
<xp:script src="/CSJS.js" clientSide="true"></xp:script>
</xp:this.resources>
<xp:panel id="APanel"
style="padding-left:10.0px;padding-right:10.0px">
<xp:table style="width:50.0%">
<xp:tr>
<xp:td>
<xp:comboBox id="ComboBox1" style="width:99.0%">
<xp:selectItems id="selectItems1">
<xp:this.value><![CDATA[#{javascript:return ""}]]></xp:this.value>
</xp:selectItems>
<xp:selectItem itemLabel="Item1"
itemValue="Value1" id="selectItem1">
</xp:selectItem>
<xp:selectItem itemLabel="Item2"
itemValue="Value2" id="selectItem2">
</xp:selectItem>
<xp:selectItem itemLabel="Item3"
itemValue="Value3" id="selectItem3">
</xp:selectItem>
<xp:selectItem itemLabel="Item4"
itemValue="Value4" id="selectItem4">
</xp:selectItem>
<xp:selectItem itemLabel="Item5"
itemValue="Value5" id="selectItem5">
</xp:selectItem>
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var dbName = session.getCurrentDatabase();
var view = ("UniNames&Abbr");
var UniList = @Unique(@DbColumn(dbName,view,1));
return UniList}]]></xp:this.value>
</xp:selectItems>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="APanel">
<xp:this.action><![CDATA[#{javascript://sessionScope.SavUniAbbr = sessionScope.UniAbbr;
var ComboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("ComboBox1").getValue();
if (!!ComboBox1) {
print("ComboBox1 = ",ComboBox1);
var type = typeof ComboBox1;
print("ComboBox1 is type ",type)
var varAlert = ComboBox1 + " is type " + type + ".";
var al = "alert('"+ varAlert +"')";
view.postScript(al);
var varAlert = "You selected " + ComboBox1 + ".";
var al = "alert('"+ varAlert +"')";
view.postScript(al);
}
}]]></xp:this.action>
</xp:eventHandler></xp:comboBox>
</xp:td>
</xp:tr>
</xp:table>
</xp:panel>
</xp:view>
非常感谢您对此的看法。 ---莉莎&安培;
答案 0 :(得分:0)
我不知道为什么会出现问题 - 但有一种解决方法。但是,我必须添加一个按钮并更改comboBox上的服务器端脚本。
1)我添加了“viewScope.SavChoice = viewScope.Choice;”到comboBox的onChange事件。 2)在按钮的onClick事件中,第一行代码是“viewScope.Choice = viewScope.SavChoice;”之后我能够使用服务器端警报来宣布事情。这是新代码:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex"
xmlns:xc="http://www.ibm.com/xsp/custom" xmlns:bz="http://www.ibm.com/xsp/bazaar">
<xp:panel id="APanel" style="padding-left:10.0px;padding-right:10.0px">
<xp:table>
<xp:tr>
<xp:td>
<xp:comboBox id="ComboBox1" value="#{viewScope.Choice}">
<xp:selectItems id="selectItems1">
<xp:this.value><![CDATA[#{javascript:return ""}]]></xp:this.value>
</xp:selectItems>
<xp:selectItem itemLabel="Item1" itemValue="Value1"
id="selectItem1">
</xp:selectItem>
<xp:selectItem itemLabel="Item2" itemValue="Value2"
id="selectItem2">
</xp:selectItem>
<xp:selectItem itemLabel="Item3" itemValue="Value3"
id="selectItem3">
</xp:selectItem>
<xp:selectItem itemLabel="Item4" itemValue="Value4"
id="selectItem4">
</xp:selectItem>
<xp:selectItem itemLabel="Item5" itemValue="Value5"
id="selectItem5">
</xp:selectItem>
<xp:selectItems id="selectItems2">
<xp:this.value><![CDATA[#{javascript:var dbName = session.getCurrentDatabase();
var view = ("UniNames&Abbr");
var UniList = @Unique(@DbColumn(dbName,view,1));
return UniList}]]></xp:this.value>
</xp:selectItems>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="APanel" id="eventHandler1">
<xp:this.action><![CDATA[#{javascript:viewScope.SavChoice = viewScope.Choice;}]]></xp:this.action>
</xp:eventHandler>
</xp:comboBox>
</xp:td>
<xp:td>
<xp:button id="button5" value="Server Side Alert">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" id="eventHandler9" refreshId="APanel">
<xp:this.script><![CDATA[XSP.getElementById("#{id:ComboBox1}").value = "";]]></xp:this.script>
<xp:this.action><![CDATA[#{javascript:viewScope.Choice = viewScope.SavChoice;
if (!!Choice) {
print("Choice = ",Choice);
var type = typeof Choice;
print("Choice is type ",type)
var varAlert = Choice + " is type " + type + ".";
var al = "alert('"+ varAlert +"')";
view.postScript(al);
var varAlert = "You selected " + Choice + ".";
var al = "alert('"+ varAlert +"')";
view.postScript(al);
}
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:td>
</xp:tr>
</xp:table>
</xp:panel>
</xp:view>