问题描述
情况:
我有一个jsp 2道场autocompleters。当它们的值被改变他们两个触发同样的操作。现在我想,在操作文件,我应该知道哪些autocompleter改变了。
I have two dojo autocompleters on a jsp. Both of them trigger the same action when their value is changed. Now I want that in the action file I should know which autocompleter was changed.
我做了什么:
通常情况下,在这种情况下我会调用JavaScript更改隐藏字段的值,然后访问该隐藏字段的值,在操作文件就知道这是改变。但是,我称之为使用的onChange属性,它(不幸)不适用于autocompleter工作的JavaScript。我不得不使用valueNotifyTopics调用的动作。
Normally, in such a situation I would call a javascript to change the value of a hidden field and then access the value of that hidden field in the action file to know which was changed. But I call the javascript using the "onChange" attribute which (unfortunately) does not work for "autocompleter". I had to use "valueNotifyTopics" for calling the action.
下面是code:
<s:url id="scriptURL" action="viewContactInfo" />
<sd:div href="%{scriptURL}" listenTopics="viewContactInfo" formId="contactInfo" showLoadingText="false" preload="false">
<s:form id="contactInfo">
<sd:autocompleter autoComplete="false" name="customer" list="customerList" valueNotifyTopics="viewContactInfo"/>
<sd:autocompleter autoComplete="false" name="contact" list="contactList" valueNotifyTopics="viewContactInfo"/>
<s:hidden id="chngd" value="initial"/>
</s:form>
</sd:div>
我希望用这样的:
I was hoping to use something like this:
onchange="dojo.byId('chngd').value='some value'; dojo.event.topic.publish('viewContactInfo');"
而不是
valueNotifyTopics="viewContactInfo"
请指教围绕我所提到的情况得到的一些方法。
Please advise some way of getting around the situation I have mentioned.
谢谢!
在情况下,我错过了所有必需的信息,请发表评论。
In case I missed out any required information please leave a comment.
推荐答案
我已经想通了这一点而回,但我现在有麻烦仍然张贴这个答案,任何人:
I had figured this out a while back, but am posting this answer now, for anyone still in trouble:
在JSP中做到这一点:
In the jsp do this:
<sd:autocompleter autoComplete="false" name="customer" list="customerList" valueNotifyTopics="topic"/>
然后在JavaScript做到这一点:
Then in javascript do this:
dojo.event.topic.subscribe("topic", function(){
dojo.byId('chngd').value='some value';
dojo.event.topic.publish('getLists');
});
这样,当一个道场autocompleter的值被改变,你可以设置隐藏字段的值就是所谓的行动之前。对于这个问题,你可以做很多更多,因为这就像,你这样做 - > 的onclick =主题()
希望这有助于!
这篇关于不能找到一种方法来传递一个隐藏值操作文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!