GWT/MVP:使用适当的 MVP 模式检测表中的更改事件

发布于 2024-09-08 12:39:50 字数 245 浏览 1 评论 0原文

我们正在使用 gwt-presenter,但实际上并不是一个特定的问题......

我有一个包含用户的表。当我在视图中构建表格(根据演示者提供的数据)时,我需要在行末尾添加两个操作按钮(“编辑”和“删除”)。

将单击处理程序分配给这些按钮以便演示者知道单击了哪个按钮的最佳方法是什么?在此之前,我们可以将私有字段从视图传递给演示者,并将离散的单击处理程序附加到该按钮。然而,这种方法相当僵化,在这种情况下效果不太好。

提前致谢。

We're using gwt-presenter, but not really a question specific to that...

I've got a table with users in it. As I build the table in the view (from the data provided by the presenter), I need to add two action buttons ("Edit", and "Delete") at the end of the row.

What's the best way to assign click handlers to these buttons so the presenter knows which was clicked? Previous to this, we could pass a private field from the view to the presenter and attach a discrete click handler to that button. However, this method is rather rigid and doesn't work in this scenario very well.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杯别 2024-09-15 12:39:50

让视图允许订阅编辑/删除单击事件,在内部注册各个行单击事件,然后将事件处理委托给视图注册的事件怎么样?

我的意思是类似以下伪代码:

View:

addRowEditClickHandler(ClickHandler handler) {
    this.rowEditClickHandler = handler; 
}
addRowDeleteClickHandler(ClickHandler handler) {
    this.rowDeleteClickHandler = handler; 
}

//... somewhere when setting up of the grid...

rowEditButton.addClickHandler = new ClickHandler() {
    onClick(args) {
        this.rowEditClickHandler.onClick(args)

}

rowDeleteButton.addClickHandler = new ClickHandler() {
    onClick(args) {
        this.rowDeleteClickHandler.onClick(args)

}

Presenter:

View view = new View();
view.addRowEditClickHandler( new ClickHandler() {
    onClick(args) {
        doSomething();
    }
});
view.addRowDeleteClickHandler( new ClickHandler() {
    onClick(args) {
        doSomething();
    }
});

How about having the view allowing the subscription for edit/delete click events, registering internally the individual row click events, and then delegating the event handling to the ones registered by the view?

I mean something like the following pesudo code:

View:

addRowEditClickHandler(ClickHandler handler) {
    this.rowEditClickHandler = handler; 
}
addRowDeleteClickHandler(ClickHandler handler) {
    this.rowDeleteClickHandler = handler; 
}

//... somewhere when setting up of the grid...

rowEditButton.addClickHandler = new ClickHandler() {
    onClick(args) {
        this.rowEditClickHandler.onClick(args)

}

rowDeleteButton.addClickHandler = new ClickHandler() {
    onClick(args) {
        this.rowDeleteClickHandler.onClick(args)

}

Presenter:

View view = new View();
view.addRowEditClickHandler( new ClickHandler() {
    onClick(args) {
        doSomething();
    }
});
view.addRowDeleteClickHandler( new ClickHandler() {
    onClick(args) {
        doSomething();
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文