gpt4 book ai didi

model-view-controller - Extjs MVC - 在 Controller 中设置存储事件

转载 作者:行者123 更新时间:2023-12-02 00:24:13 25 4
gpt4 key购买 nike

我在我的应用程序中有一个要求,我需要根据从服务器端获得的值显示 UI 组件(如文本字段、组合框)。准确地说,我在页面上有一个组合框,当用户更改值时,我需要将所选值发送到服务器以获取有关需要显示的内容的信息。在不使用 MVC 的情况下,我按如下方式实现了它

  1. 当用户更改组合框中的值时,我刷新(使用加载方法)另一个商店
  2. 当我从服务器取回数据时('datachanged' 事件),我读取数据并创建 UI 组件

现在我正在尝试使用 ExtJS MVC,所以我有两个问题

  1. 如何访问与 Controller 关联但不一定与 View 中的任何 UI 组件关联的商店
  2. 如何在 Controller 中(在控制函数中)设置商店的事件,就像我们在 View 中设置事件一样

我想在 Controller 中设置来自商店的事件,例如“datachanged”,如下所示 -

this.control({
'viewport > #content-panel' : {
render : this.createMainTabs
}
});

最佳答案

除了 sha 的回复之外,我可以说您可以在您的 Controller 中设置您的商店事件处理程序。例如,您有一个带有商店的组合框,因此您可以这样写:

this.control({
'#myCombo' : {
afterrender : this.setupStoreListeners
}
});

....

setupStoreListeners: function(combo){
var store = combo.store;
store.on('datachanged', //.....);
}

还有一件事,正如 sha 所写,您始终可以通过名称获取存储,但我仅在需要在多个 Controller 之间共享存储实例时才使用它。如果我只在一个 Controller 中需要这个商店,我只需将它保存在这个 Controller 中:

setupController: function(){
this.myStore = this.getCombo().store; // now you could use this.myStore anywhere you need

}

关于model-view-controller - Extjs MVC - 在 Controller 中设置存储事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9505568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com