【问题标题】:Sencha Touch List/Store Won't Contact ServerSencha Touch List/Store 不联系服务器
【发布时间】:2012-07-20 08:39:21
【问题描述】:

我正在尝试将 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]
    });

}
});

data.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"}
    ]
}

【问题讨论】:

  • 控制台是否有任何错误?
  • @TDeBailleul 我看到以下内容:警告无法确定响应正文的内容长度。设置响应的内容长度或设置 Response#chunked = true
  • @TDeBailleul 但是,我知道 /articles URL 处的操作没有执行,因为它设置了 puts 语句来验证其执行

标签: sencha-touch


【解决方案1】:

您的服务器脚本应返回如下所示的 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"}
    ]
}

【讨论】:

  • 感谢您的回复,@Tinashe!但是,煎茶的行为方式似乎没有什么不同。你能看出我的 index.js 或 data.js 有什么问题吗?
猜你喜欢
  • 2013-07-04
  • 2011-11-26
  • 1970-01-01
  • 2014-02-06
  • 1970-01-01
  • 2012-08-18
  • 1970-01-01
  • 1970-01-01
  • 2012-12-22
相关资源
最近更新 更多