请问datebox onChange时如何取得同listcell中的其他资料?
时间:2010-12-29
来源:互联网
如:
<listbox id="MainListBox".......>
<listcell><label value="XXX" /></listcell>
<listcell >
<datebox value="XXX" width="148px" format="yyyy-MM-dd HH:mm:ss" onChange="saveStartDt(this);"/>
</listcell>
</listbox>
在zscript的saveStartDt中写MainListBox.selectedItem.value;
希望之后可以取得同listcell中的其他资料
不过有错误:Null Pointer while evaluating: MainListBox.selectedItem.value
之前试过button onclick好像也有这样的问题~
Thanks^^
作者: eg 发布时间: 2010-12-29
这个方法在image的onclick是可以执行的
作者: eg 发布时间: 2010-12-29
出错的行数是哪里呢?
基本上在eventlistener 里面(onchange)
你可以取得任何你想要的资料
所谓listcell 的value 是你自己set 的 并不是他的小孩
<listcell value="xxx"> <...> </listcell>
作者: flyworld 发布时间: 2010-12-29
2.你确定他 selectedItem 有东西?
3.你确定你要写得是 saveStartDt(this) ,而不是 saveStartDt(self) ?
作者: Tony1223 发布时间: 2010-12-30
<listbox id="MainListBox".......>
....
<listcell >
<datebox value="XXX" format="yyyy-MM-dd HH:mm:ss" onChange="show();"/>
</listcell>
....
</listbox>
<zscript ><![CDATA[
void show(){
Listitem s = MainListBox.getSelectedItem();
if (s == null)
Messagebox.show("Select an item first");
else{
System.out.println("children="+s.getChildren().size());
for (int i=0;i<s.getChildren().size();i++){
System.out.println("i="+i+" ,"+((Listcell)s.getChildren().get( i )).getLabel());
}
}
}
]]></zscript>
更改datebox值后,是show "Select an item first"的视窗,表示MainListBox.getSelectedItem()==null
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
目前采取一个方法可解决: 把想抓的资料印出来&隐藏
<listcell >
<label value="XXX" visible="false"/>
<label value="XXX" visible="false"/>
<datebox value="XXX" format="yyyy-MM-dd HH:mm:ss" onChange="saveStartDt(self);"/>
</listcell>
<zscript ><![CDATA[
void saveStartDt(Datebox db){
Messagebox.show(((Label)db.getPreviousSibling()).getValue()+" / "+((Label)db.getPreviousSibling().getPreviousSibling()).getValue());
}
]]></zscript>
不过若位置换了or加东西 会有影响@@
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
原本希望的方法:
<listbox ..... model="@{win$composer.DataList}">
<listitem id="aseItem" self="@{each='AAA'}" value="@{AAA}">
<listcell >
<datebox value="AAA.Date" format="yyyy-MM-dd HH:mm:ss" onChange="saveStartDt(self);"/>
</listcell>
</listitem>
</listbox>
<zscript ><![CDATA[
void saveStartDt(Datebox db){
AAA pQ= (AAA) MainListBox.selectedItem.value;
//然后就能直接pQ.get值(get我包在AAA里的东西)
}
]]></zscript>
如此可以弹性取得资料 但在datebox & button中无法使用 Image可以
希望这样有比较清楚一点 感谢大家的回答
作者: eg 发布时间: 2010-12-30
看中间是不是有卡到其他window(是个有id space的家伙)
作者: Tony1223 发布时间: 2010-12-30
刚copy了您的程式 执行以后
点选hi的button alert出来是"null"
难道是因为我这里是5.0.5CE版的关系吗@@
感谢~
作者: eg 发布时间: 2011-01-03
没选的话哪来的 selectedItem ...-_-;;
这跟 CE/EE 没有关系
作者: Tony1223 发布时间: 2011-01-03
你可以Default 选一个 listitem 就不会有null了
onAfterRender="self.setSelectedIndex(0)"
作者: flyworld 发布时间: 2011-01-03
这就是我在思考的问题...
我若在每一行都加入一个button (or datebox)
点选之后 也都是alert null
也就是您说的 没选listbox 任何一栏的话就没有 selectedItem
但若今天换成每一行加一个image
点选之后 alert是有值的 不需要先点listbox 任何一栏
是我的问题太奇怪了吗XD
作者: eg 发布时间: 2011-01-03
我有试了Default 选一个 listitem
的确不会alert null
但我的需求不太能做这样的设定
我的画面:

希望user进来后 若改"开始日期"就直接存起来
所以我需要抓key值
感谢您^^
作者: eg 发布时间: 2011-01-03
你可以手动设定listbox 的selectedItem ,理论上你点行内的元素,
可以用 getParent() 取得那行的listitem ,再做setSelectedItem 的行为
作者: Tony1223 发布时间: 2011-01-03
感谢您详细解说
我有试了getParent() 方式
1 |
<window title="Listbox" border="normal"> <listbox id="MainListbox"> <listitem height="28px"> <listcell label="ZK Jet 0.8.0 is released" /> <listcell label="2008/11/17 17:41:29" /> <listcell> <datebox value="@{NpwAse.npAseDtm1}" width="148px" format="yyyy-MM-dd HH:mm:ss" onChange="saveStartDt(self);"/> </listcell> </listitem> <listitem height="28px"> <listcell label="URLs for iPhone-Optimized Google Sites" /> <listcell label="2008/11/17 15:56:37" /> <listcell> <datebox value="@{NpwAse.npAseDtm1}" width="148px" format="yyyy-MM-dd HH:mm:ss" onChange="saveStartDt(self);"/> </listcell> </listitem> <listitem height="28px"> <listcell label="Style Guide for ZK 3.5 released" /> <listcell label="2008/11/14 13:23:07" /> <listcell> <datebox value="@{NpwAse.npAseDtm1}" width="148px" format="yyyy-MM-dd HH:mm:ss" onChange="saveStartDt(self);"/> </listcell> </listitem> </listbox> <zscript ><![CDATA[ void saveStartDt(Datebox db){ ((Listbox)db.getParent().getParent().getParent()).setSelectedItem((Listitem)db.getParent().getParent()); alert(MainListbox.getSelectedItem()); } ]]></zscript> </window> |
是OK的! 我想改成这样的写法了 感谢您!!!!
作者: eg 发布时间: 2011-01-03
这样就好了
作者: Tony1223 发布时间: 2011-01-03
作者: eg 发布时间: 2011-01-03
For example,
1 |
<listbox nonselectableTags=""> <listitem><listcell><textbox/></listcell></listitem> <listitem><listcell><button label="button"/></listcell></listitem> <listitem><listcell><h:input xmlns:h="native"/></listcell></listitem> <listitem><listcell><datebox/></listcell></listitem> </listbox> |
作者: jumperchen 发布时间: 2011-01-03
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28