【问题标题】:ExtJs Controller calls view with dataExtJs 控制器用数据调用视图
【发布时间】:2014-10-07 14:30:39
【问题描述】:

我正在尝试从 AJAX 调用中调用视图,该调用编写在控制器中,同时发送存储在模型中的数据。

这是电话:

var dummyAttivita = Ext.create('appTrial.model.Attivita', {
   id: 1,
   nomeAttivita :  'il Chiosco',
   codiceAttivita: 'ago123'
});
.
.
.

doLogin: function() {
    // called whenever the Login button is tapped
    var codAttivita = Ext.getCmp('codAttivita').getValue();
    if( codAttivita != null || codAttivita !== undefined ) {
        if (codAttivita.length > 0) {
            if (codAttivita === dummyAttivita.get('codiceAttivita')) {
                Ext.Msg.alert('', 'entro', Ext.emptyFn);
                var attivitaAssociata = Ext.encode(dummyAttivita.getFields);
                Ext.Ajax.request({
                    url : 'app/view/Postazione.js/',
                    method:'POST',
                    params,: {attivitaAssociata : dummyAttivita.getFields}
                    scope : this,

                    success : function(response, opts){
                      //What should I put here???
                    },
                    //method to call when the request is a failure
                    failure : function(response, opts){
                        Ext.Msg.alert('', 'Nothing', Ext.emptyFn);
                    }
                });

            } else {
                Ext.Msg.alert('', 'Il codice inserito non è associato ad alcuna attivita', Ext.emptyFn);
            }
        } else {
            Ext.Msg.alert('', 'Inserisci il codice di una attivita', Ext.emptyFn);
        }
    }
},

我不明白的是如何加载在 url 参数中指定的新视图,同时发送存储在参数中的数据。 有人知道吗?

提前致谢

以前

【问题讨论】:

  • 那个视图是什么(表单面板、标签面板或容器),它包含什么?
  • 目前是一个简单的容器,只有html文本;我必须用调用和调用视图更新帖子吗?

标签: ajax extjs model-view-controller sencha-touch


【解决方案1】:

这应该可以解决问题

success : function(response){
    var returnJson = JSON.parse(response.responseText);

    // either work with a store or save the data somewhere else
    Ext.getStore('MyStore').add(returnJson);
    // or you use your model (if data.is the base path inside the Json
    dummyAttivita.set(returnJson.data);

    // Here you add a route (should be inside the view controller
    MyApp.app.redirectTo('newView');

    // alternative to Ext.getStore() is to use a tpl for the view
    newView.setData(returnJson);
},

【讨论】:

  • 行:"var returnJson = JSON.parse(response.responseText); 给我错误:“Uncaught SyntaxError: Unexpected token E
  • 您的回复看起来如何。你能把它写到你的帖子里吗?
  • 它包含定义在 ajax 调用的 url 属性中的模型:"response.responseText: "Ext.define('appTrial.model.Attivita'.."
  • 请。你能否请一个演示回调,以便我可以看到结果。返回的 responseText 可能不是有效的 JSON。但需要看到这一点。
  • 抱歉,Proto,感谢您的帮助,但目前我只是使用 Ext.Viewport.setActiveItem 解决了这个问题,以便加载新的蒙版。我很快就会面对它,我会带着 JSON 回来。非常感谢:)
【解决方案2】:

然后你可以像下面这样编写你的成功函数。

  success : function(response, opts){
       Ext.getCmp('container_id').setHtml(Ext.decode(response.responseText));
  },

【讨论】:

  • 不工作,但可能我没有正确解释:我有一个视图,Login.js,有一个名为 loginContainer 的容器。上面的 Ajax 调用位于 Login.js 调用的控制器内部。现在,在 AJAX 调用的 onSuccess 上,我将调用 Postazione.js,定义在由 postazioneContainer 进行的 ajax 调用的 url 上,位于登录视图的位置。
猜你喜欢
  • 2015-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 2020-03-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多