2012-04-13 53 views
3

我在几个月前潜入gwt世界,现在正在尝试使用gwt-query库。 我跟着本教程:http://code.google.com/p/gwtquery/wiki/GettingStarted 因为我在Modle-View-Presenter中工作,我尝试在View中实现上面的教程(绑定到..View.ui.xml),但它似乎工作。Gwt-query对我的MVP不起作用。

我试图创建一个拉布勒,然后运行该代码:

列表allGwtLabels = $( “GWT-标签”。)窗口小部件();

但它没有选择任何东西!

我想我有我想要的qwtQuery搜索小部件(点我具体ui.xml文件)

什么我做错了以某种方式点?

在此先感谢。下面是我的我的演示+查看+ XML即dosent工作的代码:

//================================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> 
+0

谢谢。它适用于List allGwtLabels = $(“。gwt-Label”,widget).widgets();但我仍然无法使这项工作:$(标签,_html)。单击(新功能(){ \t \t \t @覆盖 \t \t \t公共无效F(部件w){ \t \t \t \t //褪色out of the label $(w,_html).fadeOut(1000); \t \t \t} \t \t}); – Michael 2012-04-14 16:21:23

回答

2

尝试:清单allGwtLabels = $( “GWT-标签”,窗口小部件).widgets();

您必须指定元素的容器,因为当您试图查询它们时,元素未连接到dom。

+0

我设法通过使用gwt clickHandler来做到这一点。但是它是“干净”还是应该保持并尝试使用GQuery点击方法进行此项工作?这个工程:label.addClickHandler(新clickHandler事件(){ \t \t \t \t \t \t @覆盖 \t \t \t公共无效的onClick(ClickEvent事件){ \t \t \t \t $(标签).fadeOut(1000); \t \t \t} \t \t}); – Michael 2012-04-14 16:58:10

+0

_html.add(label); $(标签)。单击(新功能(){ 公共无效F(){// 淡出标签 $(标签).fadeOut(1000);} }); 应该工作 – jdramaix 2012-04-15 19:47:30