0

我正在尝试从我的应用程序中的 json 文件加载数据,但没有加载数据,我被困住了:

(型号)Singers.js:

Ext.define('SGM.model.Singers', {
extend: 'Ext.data.Model',
fields: ['id', 'ten_that', 'nghe_danh', 'ngay_sinh', 'tieu_su', 'anh_dai_dien', 'luot_like'],
idProperty: 'id',
proxy: {
    type: 'ajax',
    url: 'data/singers.json',
    reader: {
        type: 'json',
        root: 'data',
        successProperty: 'success'
    }
}

});

(商店)Singers.js

Ext.define('SGM.store.Singers', {
extend: 'Ext.data.Store',
model: 'SGM.model.Singers',
/*data:[
    {   id: 1,
        ten_that: "Bui Anh Tuan",
        nghe_danh: "Bui Anh Tuan",
        ngay_sinh:"20/9/1992",
        tieu_su: "Tieu su cua Bui Anh Tuan",
        anh_dai_dien:"buianhtuan.jpg",
        luot_like:100}, 
    {
        id: 2, 
        ten_that: "Cao Mi Kim", 
        nghe_danh: "Cao Mi Kim", 
        ngay_sinh:"20/9/1992", 
        tieu_su: "Tieu su cua Cao Mi Kim", 
        anh_dai_dien:"caomikim.jpg", 
        luot_like:100}, 
    {
        id: 3,
        ten_that: "Pham Khanh Phuong", 
        nghe_danh: "Khanh Phuong", 
        ngay_sinh:"20/9/1992", 
        tieu_su: "Tieu su cua Khanh Phuong", 
        anh_dai_dien:"khanhphuong.jpg", 
        luot_like:100}, 
    {
        id: 4, 
        ten_that: "Ho Quang Hieu", 
        nghe_danh: "Ho Quang Hieu", 
        ngay_sinh:"20/9/1992", 
        tieu_su: "Tieu su cua Ho Quang Hieu", 
        anh_dai_dien:"hoquanhieu.jpg", 
        luot_like:100}
],*/

});

上面的内联数据运行良好,但是当我使用以下代码创建一个单独的 json 文件时:singers.js(在文件夹“数据”中):

{
"success": true,    
"results": [
    {   "id": 1,
        "ten_that": "Bui Anh Tuan",
        "nghe_danh": "Bui Anh Tuan",
        "ngay_sinh":"20/9/1992",
        "tieu_su": "Tieu su cua Bui Anh Tuan",
        "anh_dai_dien": "buianhtuan.jpg",
        "luot_like": 100}, 
    {
        "id": 2, 
        "ten_that": "Cao Mi Kim", 
        "nghe_danh": "Cao Mi Kim", 
        "ngay_sinh": "20/9/1992", 
        "tieu_su": "Tieu su cua Cao Mi Kim", 
        "anh_dai_dien": "caomikim.jpg", 
        "luot_like":100}, 
    {
        "id": 3,
        "ten_that": "Pham Khanh Phuong", 
        "nghe_danh": "Khanh Phuong", 
        "ngay_sinh": "20/9/1992", 
        "tieu_su": "Tieu su cua Khanh Phuong", 
        "anh_dai_dien": "khanhphuong.jpg", 
        "luot_like": 100}, 
    {
        "id": 4, 
        "ten_that": "Ho Quang Hieu", 
        "nghe_danh": "Ho Quang Hieu", 
        "ngay_sinh": "20/9/1992", 
        "tieu_su": "Tieu su cua Ho Quang Hieu", 
        "anh_dai_dien": "hoquanhieu.jpg", 
        "luot_like": 100}
]

}

这是我的文件夹目录:

+app
++controller
++model
+++Singers.js
++store
+++Singers.js
+view
+data
++singers.json
+app.js

-index.html.js

提前感谢!

4

1 回答 1

0

The error lies in the root property of your proxy/reader configuration. Here, you specify the value "data" as the root object, in your JSON file however, the objects are stored in the "results" property.

Try the following model definition (mind the value of root):

Ext.define('SGM.model.Singers', {
  extend: 'Ext.data.Model',
  fields: ['id', 'ten_that', 'nghe_danh', 'ngay_sinh', 'tieu_su', 'anh_dai_dien', 'luot_like'],
  idProperty: 'id',
  proxy: {
    type: 'ajax',
    url: 'data/singers.json',
    reader: {
      type: 'json',
      root: 'results',
      successProperty: 'success'
    }
  }
});
于 2013-09-14T14:56:24.617 回答