YQL在sencha中触摸MVC

时间:2014-07-17 12:29:23

标签: sencha-touch sencha-touch-2 sencha-touch-2.1

我正在寻找一些关于YQL解释MVC架构的博客或示例。我觉得很难理解厨房水槽的例子。任何人都可以在YQL上共享简单的MVC。所以它对其他人也有帮助。

1 个答案:

答案 0 :(得分:3)

我不了解YQL,但根据链接user3849047,它基本上是针对某些远程api的请求。因此,整合可能比本草案更棘手。

基本上,这就是它应该如何运作。

您将从api调用中获得某种数据。此数据可以表示为Ext.data.Model。在Ext.data.Store中组织并存储了一堆模型。

所以你要做的就是以某种方式填充商店。 有两种方式。

在您的控制器中执行此操作:

Ext.create("Controller", {
    extend: "Ext.app.Controller",

    getStoreData: function () {
        var me = this;
        Ext.data.JsonP.request({
            url: "yqlRequestUrl",
            params: {
                // request parameter
            },
            success: function ( result, request ) {
                me.fillStore( result );
            }
        });
    },

    fillStore: function ( result ) {
        var data = transformResultIntoModels( result );
        var store = Ext.getStore("myStore");
        store.add( data );
    }
});

您可以自己执行api请求并将响应转换为模型。

或者让你的商店为你做这件事:

Ext.define("MyStore", {
    extend: "Ext.data.Store",

    autoLoad: false,
    storeId: "mystore",
    model: "MyModel",
    proxy: {
        type: "jsonP",
        url: "yqlRequestUrl",
        extraParams: {
            // request parameter
        },
        reader: {
            type: "json",
            rootProperty: "yourRootElement"
        }
    }
});

由于此商店设置为autoLoad: false,您必须通过

手动加载商店
store.load({ 
    callback: function ( records, operation, success ) {
    },
    scope: this
});