問題描述
Cửa hàng Sencha Touch 2 đạt kỷ lục (Sencha Touch 2 store get record)
I have a problem.
I have 2 store files (1 event and 1 places). I'm loading these stores from a database. Now the problem is that in the event store there is a field called {id_place}. This field contains a number which is also a number in the places store. Now what I need to do is get the name from the place of the {id_place}. So the {name} is a field in the places store. So what I need is a function to get a record from another store and then get the {name} from that store. So I send the id_place to the placestore, then I need to find the record with that id and I need to get the field {name} from that record. I don't know if I'm making sense, it's kinda hard to explain. I hope this can be done.
Thanks in advance!
Edit:
showPlace: function(id_place){
var placeUrl = 'http://admin.hishanghai.info/sencha/places.php?action=read&callback=callback&id=' + id_place;
store = new Ext.data.Store({
model: 'android.model.Placesmodel',
autoLoad: true,
proxy: {
type: 'scripttag',
url: placeUrl,
reader: {
type: 'json',
rootProperty: 'place'
},
extraParams: {
action: 'read'
}
}
})
//var naam = Ext.getStore('Placesstore').getById('id_place').get('name')
//var Record = store.getAt(id_place);
//var naam = store.getById('id_place').get('name');
var naam = store.get('name');
return naam;
}
This code creates a store with the info from 1 record. Now I only need to access the name field. how do i do that?
參考解法
方法 1:
found it:
showPlace: function(id_place){
var placesstore = Ext.getStore('Placesstore');
var i =0;
var placeid = 0;
var aRecord;
while(placeid != id_place){
aRecord = placesstore.getAt(i);
placeid = aRecord.data.id;
i+=1;
}
var naam = aRecord.data.name;
return naam;
}
(by Bjorn Ravers、Bjorn Ravers)