0

我正在尝试将 Sencha Touch 2 前端与 Rails 后端(返回 JSON)放在一起。但是,我发现运行以下脚本根本不会联系服务器。我相信这个问题有一个非常简单的解决方案!如果我将行添加:autoLoad: true到我的商店,则连接服务器,但我在浏览器中看到一个永无止境的加载图像。

非常感谢您的帮助!如果您想查看更多信息,请让我知道。

——贾里德

index.js

ListDemo = new Ext.Application({

name: "ListDemo",

launch: function() {

    ListDemo.listPanel = new Ext.List({
        id: 'disclosurelist',
        store: ListDemo.ListStore,
        itemTpl: '<div class="contact">{title}</div>',
        onItemDisclosure: function(record, btn, index) {
            ListDemo.detailPanel.update(record.data);
            ListDemo.Viewport.setActiveItem('detailpanel');
        }
    });

    ListDemo.Viewport = new Ext.Panel ({
        fullscreen: true,
        layout: 'card',
        cardSwitchAnimation: 'slide',
        items: [ListDemo.listPanel]
    });

}
});

数据.js

Ext.regModel('Article', {
        fields: [
            {name: 'title',       type: 'string'},
                    {name: 'url',     type: 'string'}
        ],
        proxy: {
          type: 'rest',
          url : 'articles',
            format: 'json',
          reader: {
              type: 'json',
              root: 'articles',
                record: 'entry'
          }
      }
});

ListDemo.ListStore = new Ext.data.Store({
        model: 'Article'
})

如果我访问 localhost:3000/articles.json,这是服务器响应的内容:

{"articles":
    [
        {"created_at":"2012-07-18T23:54:08Z","from":null,"id":1,"image":"","title":"Inquiry Seeks Accomplices of Bomber in Bulgaria","updated_at":"2012-07-21T06:13:54Z","url":"www.newyorktimes.com"},
        {"created_at":"2012-07-19T00:01:35Z","from":null,"id":2,"image":"","title":"Changing Harlem Celebrates Queen of Soul Food","updated_at":"2012-07-21T06:26:13Z","url":"www.newyorktimes.com/harlem"}
    ]
}
4

1 回答 1

0

您的服务器脚本应返回如下所示的 JSON:

{
    "success": true,
    "articles": [
        {"created_at":"2012-07-18T23:54:08Z","from":null,"id":1,"image":"","title":"Inquiry Seeks Accomplices of Bomber in Bulgaria","updated_at":"2012-07-21T06:13:54Z","url":"www.newyorktimes.com"},
        {"created_at":"2012-07-19T00:01:35Z","from":null,"id":2,"image":"","title":"Changing Harlem Celebrates Queen of Soul Food","updated_at":"2012-07-21T06:26:13Z","url":"www.newyorktimes.com/harlem"}
    ]
}
于 2012-07-22T08:39:40.787 回答