ฉันโหลดร้านค้า json ไว้แล้ว ฉันต้องคว้าหนึ่งบันทึกจากมัน ฉันใช้ : getAt(index)
, find()
, getById()
แต่ไม่มีผลลัพธ์ นี่คือรหัสของฉัน:
var appSettingReader = new Ext.data.JsonReader({
root: 'results',
},[
{name: 'id', type: 'int', mapping: 'id'},
{name: 'projetId', type: 'int', mapping: 'projetId'},
{name: 'resLevels', type: 'int', mapping: 'resLevels'},
{name: 'maxResToLock', type: 'int', mapping: 'maxResToLock'},
{name: 'maxTimeToLock', type: 'int', mapping: 'maxTimeToLock'},
{name: 'infosToPrint', type: 'string', mapping: 'infosToPrint'}
])
var appSettingStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'inc/getSettings.php',
method: 'POST'
}),
baseParams:{task: "app"},
reader : appSettingReader,
sortInfo:{field: 'id', direction: "DESC"}
})
appSettingStore.load();
รหัสนี้ส่งคืนไม่ได้กำหนด:
console.log(appSettingStore.getAt(0));
console.log(appSettingStore.find("id","1"));
นี่คือสตริง json ที่ส่งคืนจากเซิร์ฟเวอร์:
{success:true,"results":[{"id":"1","projetId":"1","resLevels":"1","maxResToLock":"40","maxTimeToLock":"10","infosToPrint":"1_2_3_5","hotlineMail":"[email protected]"}]}
ฉันได้ทดสอบรหัสนี้ด้วย:
var records = new Array()
var test = appSettingStore.each(function(rec){
records.push(rec)
})
console.log(records)
และฉันได้รับอาร์เรย์ว่าง !
PS : ร้านค้านี้ไม่ผูกพันกับส่วนประกอบใดๆ ฉันแค่อยากอ่านและเขียนถึงมัน