几个月前我潜入了 gwt 世界,现在正在尝试使用 gwt-query 库。我遵循了本教程:http ://code.google.com/p/gwtquery/wiki/GettingStarted 因为我在 Modle-View-Presenter 中工作,所以我尝试在我的视图中实现上述教程(绑定到 .. View.ui.xml),但它似乎工作。
我尝试创建一个标签,然后运行代码:
列出所有GwtLabels = $(".gwt-Label").widgets();
但它什么也没选择!
我想我必须以某种方式指出我希望 qwtQuery 搜索小部件的位置(指向我的特定 ui.xml 文件)
我究竟做错了什么?
提前致谢。下面是我的 Presenter + View + xml 的代码,它可以工作:
//================================Presenter=================================:
public class QueryPresenter extends
Presenter<QueryPresenter.MyView, QueryPresenter.MyProxy> {
public interface MyView extends View {
}
@ProxyCodeSplit
@NameToken(NameTokens.query)
public interface MyProxy extends ProxyPlace<QueryPresenter> {
}
@Inject
public QueryPresenter(final EventBus eventBus, final MyView view,
final MyProxy proxy) {
super(eventBus, view, proxy);
}
@Override
protected void revealInParent() {
RevealRootContentEvent.fire(this, this);
}
@Override
protected void onBind() {
super.onBind();
}
}
//====================================View============================================:
public class QueryView extends ViewImpl implements QueryPresenter.MyView {
private final Widget widget;
public interface Binder extends UiBinder<Widget, QueryView> {
}
@Inject
public QueryView(final Binder binder) {
widget = binder.createAndBindUi(this);
List<Widget> allGwtLabels = $(".gwt-Label").widgets(); //Doesn't Work!!
//Also doesn't work!!
Label label = new Label("Click on me and I will disappear");
$(label).click(new Function() {
@Override
public void f(Widget w) {
//fade out the label
$(w).fadeOut(1000);
}
});
_html.add(label);
//retrieve all attached gwt labels
}
@Override
public Widget asWidget() {
return widget;
}
@UiField Label _label;
@UiField HTMLPanel _html;
}
//==================xml file===============================
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys='com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator'
ui:generateLocales='default'>
<g:HTMLPanel ui:field="_html">
<script type="text/javascript" language="javascript" src="gquerytest/gquerytest.nocache.js"></script>
<g:Label text="hey" ui:field="_label"/>
</g:HTMLPanel>
</ui:UiBinder>