2013-07-16 125 views
0

我想從我的users.json中獲取成功屬性。我怎樣才能訪問它?此代碼從here在sencha touch中獲取本地存儲javascript文件的屬性

{ 
    "success": true, 
    "users": [ 
     { 
      "firstName": "Tommy", 
      "lastName": "Maintz", 
      "age": 24, 
      "eyeColor": "green" 
     }, 
     { 
      "firstName": "Aaron", 
      "lastName": "Conran", 
      "age": 26, 
      "eyeColor": "blue" 
     }, 
     { 
      "firstName": "Jamie", 
      "lastName": "Avins", 
      "age": 37, 
      "eyeColor": "brown" 
     } 
    ] 
} 

代碼:

// Set up a model to use in our Store 
Ext.define("User", { 
    extend: "Ext.data.Model", 
    config: { 
     fields: [ 
      {name: "firstName", type: "string"}, 
      {name: "lastName", type: "string"}, 
      {name: "age",  type: "int"}, 
      {name: "eyeColor", type: "string"} 
     ] 
    } 
}); 

var myStore = Ext.create("Ext.data.Store", { 
    model: "User", 
    proxy: { 
     type: "ajax", 
     url : "/users.json", 
     reader: { 
      type: "json", 
      rootProperty: "users" 
     } 
    }, 
    autoLoad: true 
}); 

Ext.create("Ext.List", { 
    fullscreen: true, 
    store: myStore, 
    itemTpl: "{lastName}, {firstName} ({age})" 
}); 
+0

你得到任何錯誤? – Viswa

+0

不,這是行得通的。但我怎樣才能訪問成功的財產?我試圖從我的商店中的Object中找到它,但我找不到任何東西。 – Niklas

+1

您爲什麼不在代理讀取器中設置successProperty?如果你想處理異常使用成功..然後我認爲你需要看看下面的鏈接[link1](http://www.sencha.com/forum/showthread.php?129380-how-i-can-to -use-successProperty-for-json-response)[link2](http://www.sencha.com/forum/showthread.php?135143-RESTful-Model-How-to-indicate-that-the-PUT-operation - 失敗)[link3](http://www.sencha.com/forum/showthread.php?126656-Where-to-trap-Store-Proxy-exception/page2) – Viswa

回答

0

,您就能獲得成功財產與

var success = myStore._proxy._reader.rawData.success; 
相關問題