-1

我正在寻找 sencha touch 2 MVC STORE 的教程或示例,它处理 Jsonp 链接并从那里获取数据,只有 MVC BASE。我需要了解 Store、Model、Controller 和 View 如何在基于 MVC 的结构中相互交互。有什么建议吗?之间我需要了解如何获取和使用 jsonp 链接和数据,谢谢

4

4 回答 4

1

一个简单的使用 jsonp 的模型、存储和视图示例

jsonp 的样子。

callback({"Message":"Success","Post":[{"id":"35","UserId":"faisalkhalid690","Content":"lol","Time":"2013-12-03 05:28:15"},{"id":"50","UserId":"faisalkhalid","Content":"asdfasdfasdf","Time":"2013-12-03 05:52:27"},{"id":"51","UserId":"faisalkhalid","Content":"sadfasdfasdf","Time":"2013-12-03 05:52:38"},{"id":"52","UserId":"faisalkhalid","Content":"holloa","Time":"2013-12-03 05:52:50"},{"id":"70","UserId":"faisalkhalid690","Content":"hello","Time":"2013-12-04 23:22:52"}]});

此 jsonp 的模型。

Ext.define('talkbag.model.Comments', {
    extend: 'Ext.data.Model',

    config: {
           idProperty: 'id',
        fields: [
            { name: 'id', type: 'auto' },
            { name: 'UserId', type: 'auto' },
            { name: 'Content', type: 'auto' },
            { name: 'Time', type: 'auto' }

        ]
    }
});

店铺:

Ext.define('talkbag.store.Comments', {
extend:'Ext.data.Store',

storeId:'Comments',
config:{
    autoLoad: true,
       model:'talkbag.model.Comments',
         proxy: {
            type: 'jsonp',
            url : 'http://www.litemake.com/ViewComments.php?Pid='+talkbag.User.PostId,
            reader: {
                type: 'json',
                rootProperty: 'Post'
            }
        }
    }

});

看法:

Ext.define('talkbag.view.ViewPost.ViewCommentDetail', {

xtype:'ViewCommentDetail',
extend:'Ext.dataview.List',
config:{
  store:'Comments', 
itemTpl:'<table><tr><td width="80px"><table align="center"><tr><td align="center"><img src="http://www.litemake.com/getPic.php?userId={UserId}" heigth="30px" width="30px"/></td></tr><tr><td style="font-size:0.6em">{UserId}</td></tr></table></td><td style="padding-left:20px"><table><tr><td style="font-size:0.7em; padding:0px 0px 5px 0px">{Content}</td></tr><tr><td style="font-size:0.5em">{Time}</td></tr></table></td></tr></table>'

}

});
于 2013-12-10T11:41:51.133 回答
1

下载 sencha touch 2 并找到 oreilly 示例。在关于面板推文页面的此示例中,从商店加载数据(阅读器类型为 jsonp)。您还应该查看其他示例,例如 touchtweets、geocongress、navigationview 等。我认为这是最好的开始方式。

于 2012-05-25T08:05:03.423 回答
1

如果您需要有关 JSONP - 服务器端的一些信息,请查看 Sencha Touch API (JSONP)

在那里,您可以找到服务器端方法来处理您对常见服务器端编程语言(如 PHP、Java 或 ASP.net)的 JSONP 请求。

对于 PHP,它看起来像这样:

// From your Sencha JSONP Store, you will get a callback parameter which we
// need to put in our $callback var, for later usage.
$callback = $_REQUEST['callback'];


// Create the output object.
// this could also be a database output, but remember to      
// convert it into an array
$output = array('a' => 'Apple', 'b' => 'Banana');

// start output
// this section switches between a jsonp callback or usual json output.
if ($callback) {
    header('Content-Type: text/javascript');
    echo $callback . '(' . json_encode($output) . ');';
} else {
    header('Content-Type: application/x-json');
    echo json_encode($output);
}

正如 Faisal Khalid 已经说过的那样,输出看起来像......

myCallbackName({
    "message":"success",
    "total":2,
    "data":[
             {"prename":"Bob","lastname":"example"},
             {"prename":"John","lastname":"Beard"}
           ]
});

...您已将 myCallbackName 定义为sencha应用程序(存储配置)中的回调名称。

该配置称为callbackKey并且默认设置为回调

于 2014-07-22T08:12:19.593 回答
1

我发现文档中有很多关于理解 sencha touch 的 MVC 结构的很好的教程,以及每个单独的主题,如商店和模型。

MVC 深入第 1 部分: http ://docs.sencha.com/touch/2-0/#!/video/mvc-part-1

MVC 深度第 2 部分: http ://docs.sencha.com/touch/2-0/#!/video/mvc-part-2

该文档还有一个指南部分,涵盖了您也需要了解的所有内容。 http://docs.sencha.com/touch/2-0/#!/guide

于 2013-03-25T06:23:52.537 回答