我试图使用SuggestBox和MultiWordSuggestOracle显示图标和建议中的文本,如下代码所示:
public class Suggestions implements Suggestion {
private String suggestion;
public Suggestions(){}
public Suggestions(String suggestion){
this.suggestion = new String( suggestion );
}
@Override
public String getDisplayString() {
return ( suggestion + " <img src='/images/image.png'/> " );
}
@Override
public String getReplacementString() {
return suggestion;
}}在onModuleLoad函数中包含以下代码:
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(){
@Override
public boolean isDisplayStringHTML() {
return true;
}};
oracle.add(new Suggestions("A").getDisplayString());
SuggestBox suggestionBox = new SuggestBox(oracle);问题: html代码被打印为普通文本。你们能建议一下密码有什么问题吗?
谢谢!
发布于 2014-08-11 00:14:28
因为你的建议课从未被使用过!
多字甲骨文只有显示字符串,并创建自己的建议项。
只需重写甲骨文中的methode createSuggestion:
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(){
@Override
public boolean isDisplayStringHTML() {
return true;
}
@Override
protected MultiWordSuggestion createSuggestion(String replacementString, String displayString) {
return new Suggestions(replacementString);
}
};
oracle.add(new Suggestions("A").getDisplayString());
SuggestBox suggestionBox = new SuggestBox(oracle);发布于 2014-08-12 16:46:11
下面是我做了什么,让image+text在建议下降。
public class Suggestions implements Suggestion {
private String suggestion;
public Suggestions(){}
public Suggestions(String suggestion){
this.suggestion = new String( suggestion );
}
@Override
public String getDisplayString() {
return ( suggestion + new Image('/images/image.png') );
}
@Override
public String getReplacementString() {
return suggestion;
}}
OnModuleLoad function is:
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(){
@Override
public boolean isDisplayStringHTML() {
return true;
}
@Override
protected MultiWordSuggestion createSuggestion(String replacementString, String displayString) {
return new Suggestions(replacementString);
}
};
oracle.add("A");
SuggestBox suggestionBox = new SuggestBox(oracle);https://stackoverflow.com/questions/25230667
复制相似问题