所以我有一个商店
Ext.define('APN.store.BackupShow', { extend: 'Ext.data.Store', requires: [ 'APN.model.ScheduledShow' ], config: { model: 'APN.model.ScheduledShow', proxy: { type: 'ajax', url: '', reader: { type: 'xml', record: 'item', rootProperty: 'xml' } } }, getShow: function () { if (this.getData().length greater 1) # by some reason stackoverflow didn't allow me to put greater sign in here; return null; // Copy field data across as wrong field is popped. this.getAt(0).set("listimage", this.getAt(0).get("onairimage")); this.getAt(0).set("isbackup", "true"); return this.getAt(0); } });
当我试图调用商店的第一个元素时,我得到undefined
,但该元素存在于商店中:
(0) console.log(backupShowStore); (1) console.log(backupShowStore.data); (2) console.log(backupShowStore.getData().all); (3) console.log(backupShowStore.getData().all.length); (4) console.log(backupShowStore.getData().all.getAt(0));
我回来了:
(1)
Class _data: Class _model: function () { _modelDefaults: objectClass _proxy: Class _remoteFilter: false _remoteSort: false _storeId: "backupShow" _totalCount: null config: objectClass data: Class _autoFilter: true _autoSort: true _filterRoot: "data" _sortRoot: "data" all: Array[1] 0: Class _data: Object data: Object bufferingProgress: null contentlink: null description: null facebooklink: "http://www.facebook.com/mixmelbourne" id: "ext-record-45" isbackup: null listimage: null onairimage: "http://arntrnassets.mediaspanonline.com/radio/mxm/53808/on-air-default_v3.png" showbody: "Melbourne's widest variety from 2K to today, Mix101.1 with Chrissie & Jane waking up Melbourne weekdays from 6am." showbyline: "The widest variety from 2K to today" showcontentxml: null showemail: null showname: "Mix 101.1" showschedule: null smallimage: null title: null twittername: "mixmelbourne" __proto__: Object id: "ext-record-45" internalId: "ext-record-45" modified: Object phantom: true raw: item stores: Array[1] __proto__: TemplateClass length: 1 __proto__: Array[0]
(2)
_autoFilter: true _autoSort: true _filterRoot: "data" _sortRoot: "data" all: Array[1] config: objectClass dirtyIndices: true getKey: function (record) { indices: Object initConfig: function (){} initialConfig: Object items: Array[1] keys: Array[1] length: 1 map: Object __proto__: TemplateClass
(3)
Array[1] 0: Class length: 1 __proto__: Array[0]
(4)
0
(5)
Uncaught TypeError: Object [object Array] has no method 'getAt'
对于(5)这是可以理解的,因为数组没有方法getAt,但是商店没有任何项目,并且由(4)表示getData元素的数组等于0 ...
此时此刻与Sencha Touch Framework非常混淆,以及如何获取元素数组的第一个元素
答案 0 :(得分:1)
为什么不使用Ext.data.Store.first() method。
我发现当我使用api提供的方法时,我通常是一个更开心的开发人员。在极少数情况下,我需要一些未提供的东西,我会亲自浏览Sencha Objects,但我真的不想这样做。
让我知道该解决方案是否以及为何不起作用,我会尝试为您找到其他内容。