0

JSON ファイルからストアへのデータのインポート

フロントエンドのデザインに Sencha Touch を使用し、バックエンドのデータベースのクエリに Java を使用するアプリの開発を開始しました。ただし、2つを統合するのに問題があります。Java クエリからのデータを json 形式の .json ファイルに返してから、それをストア経由でアプリにロードしようとしましたが、機能していないようです。以下に示すように、Chrome コンソールにエラーが表示されます。

オプション localhost:8080/ProficyAppData/WebContent/app/store/info.json?_dc=1342618907990&page=1&start=0&limit=25 リソースの読み込みに失敗しました

私のプロジェクトはEclipse Java Web Projectに含まれているので、localhostサーバーを簡単に利用できます。json データがストアにロードされない理由がわかりません。

店:

Ext.define('MyApp.store.Questions', {
extend: 'Ext.data.Store',

config: {
autoLoad: true,
model: 'MyApp.model.Question',

proxy: {
type: 'ajax', 
url: 'localhost:8080/ProficyAppData/WebContent/app/store/info.json',
reader: 'json'
},
listeners: {
load: function() {
console.log(this);
}
},
}
});

モデル:

Ext.define('MyApp.model.Question', {
extend: 'Ext.data.Model',

config: {
fields: ['id', 'criteria', 'description', 'questionName', 'type']
}
});

info.json:

[
     {
          "id": 1,
          "criteria": "no criteria yet",
          "description": "no description yet",
          "questionName": "no question yet",
          "type": "n/a"
     },
     {
          "id": 2,
          "criteria": "no criteria yet",
          "description": "no description yet",
          "questionName": "no question yet",
          "type": "n/a"
     },
     {
          "id": 3,
          "criteria": "no criteria yet",
          "description": "no description yet",
          "questionName": "no question yet",
          "type": "n/a"
     },
     {
          "id": 4,
          "criteria": "no criteria yet",
          "description": "no description yet",
          "questionName": "no question yet",
          "type": "n/a"
     },
     {
          "id": 5,
          "criteria": "no criteria yet",
          "description": "no description yet",
          "questionName": "no question yet",
          "type": "n/a"
     },
     {
          "id": 6,
          "criteria": "no criteria yet",
          "description": "no description yet",
          "questionName": "no question yet",
          "type": "n/a"

     }
]


  [1]: http://i.stack.imgur.com/3zxuD.png
4

2 に答える 2

1

私はあなたの質問にどのような種類の一致するかを思いついた同様のサンプルを持っています...見てください

モデル:

 Ext.define('MyApp.model.user',{
 extend: 'Ext.data.Model',


   config: {

        identifier:{
          type:'uuid'
        },
       fields: [
        {
          name:'id',
          type:'string'
        },

       {
          name: 'name',
          type:'string'
       },
       {
          name: 'mobile',
          type:'number'
       },
        {
          name: 'birthday',
          type:'date'
       },
       {
          name: 'email',
          type:'email'
       },
        {
          name: 'password',
          type:'password'
       },
       {
          name:'haveid',
          type:'boolean'
       },
       {
        name:'photo'
       }
       ],

 }});

お店:

Ext.define('MyApp.store.UserStore',{
extend:'Ext.data.Store',

   config: {
    model: 'MyApp.model.user',
    storeId: 'userstore',
    autoload:true,
    proxy: {
        type: 'ajax',
        id: 'userstoreproxy',
        url:'./resources/json/user.json',
        method:'POST',

    // .../RESOURCES/JSON/USER.JSON
        reader:
        {
            type:'json',
            rootProperty:'form.fields'
        }


    }
}});

ビューに追加するリスナー:

listeners:{
painted:function()
{
    var store=Ext.getStore('userstore');

    store.load({
        callback:function(records)
        {
            localStorage.name=records[0].getData().name;
            localStorage.mobile=records[0].getData().mobile;
            localStorage.birthday=records[0].getData().birthday;
            localStorage.email=records[0].getData().email;
            localStorage.password=records[0].getData().password;


        }

    });
    console.log(store.data);
    // var data=JSON.parse(store.data);
    // console.log(data);        
    var record=store.getAt();
    console.log(record);
     // var bday=localStorage.birthday;
     // if(bday)
     // {
     //    bday.setHours(0);
     //    bday.setMinutes(0);
     //    bday.setSeconds(0);
     //    bday.setMilliseconds(0);
     // }
     // console.log(bday);
    Ext.getCmp('name').setValue(localStorage.name);
    Ext.getCmp('mobile').setValue(localStorage.mobile);
     Ext.getCmp('birthday').setValue();
    Ext.getCmp('email').setValue(localStorage.email);
     Ext.getCmp('password').setValue(localStorage.password);

}}

コントローラー:

Ext.define('MyApp.controller.usercontroller', {
extend: 'Ext.app.Controller',

config: {
    control: {
       save: {
            tap: 'FormSave'
        }

    },

    refs: {
        form:'basicform',
        save: 'button[action=save]'

    }
},

FormSave: function(button,e,options){

  var details=this.getForm().getValues();
  console.log(details);
  var userStore = Ext.getStore('userstore');
  userStore.add(details);
  userStore.sync();
  console.log(details.id);
  Ext.Msg.alert('SUCCESS', 'Data Saved to Local Storage Successfully');}});

plsは適切なビューとjsonを書きます..これは誕生日を除いてうまくいくはずです

于 2014-08-02T05:57:52.957 に答える
0

次のように、お気に入りのブラウザからアプリを起動できます。

http://localhost:8080/ProficyAppData/your_name_app.html

これが役立つことを願っています。:)

于 2012-07-18T20:05:14.443 に答える