0
私の問題は、関連付けによってデータを取得できないことにあります。 コンソールからsetup()を実行した後、firstTurbine.getPlant()は関連するプラントを返すと予想されますが、未定義を返します。 私はおそらく正しい場所を探していないだろう解決策を探して多くの時間を費やしました。 belongsTo関連によって作成データモデル:Association getter returns undefined
Ext.regApplication({
name: "app",
launch: function() {
//app.views.viewport = new app.views.Viewport();
}
});
app.models.Plant = Ext.regModel("Plant", {
fields: [
{name: "id", type: "int"},
{name: "name", type: "string"},
{name: "notes", type: "auto"}
],
proxy: {type: 'localstorage', id:'plantStorage'}
});
app.models.Turbine = Ext.regModel("Turbine", {
fields: [
{name: "id", type: "int"},
{name: "plant_id", type: "int"},
{name: "name", type: "string"},
{name: "notes", type: "auto"}
],
proxy: {type: 'localstorage', id:'turbineStorage'},
belongsTo: 'Plant'
});
app.stores.plants = new Ext.data.Store({
model: "Plant",
autoLoad: true,
data : [
{id: 1, name: 'Plant1', notes: ["Note1", "Note2"]},
{id: 2, name: 'Plant2', notes: ["Note1", "Note2"]},
{id: 3, name: 'Plant3', notes: ["Note1", "Note2"]}
]
});
app.stores.turbines = new Ext.data.Store({
model: "Turbine",
autoLoad: true,
data: [
{id: 11, "plant_id": 1, name: "T41", notes: ["Turbine note 1", "Turbine note 2"]},
{id: 12, "plant_id": 1, name: "T13", notes: ["Turbine note 1", "Turbine note 2"]}
]
});
function setup(){
firstPlant = app.stores.plants.getAt(0);
if(!firstPlant){
firstPlant = Ext.ModelMgr.create({name:"TestPlant1", id: 1}, "Plant");
app.stores.plants.add(firstPlant);
app.stores.plants.sync();
}
firstTurbine = app.stores.turbines.getAt(0);
if(!firstTurbine){
firstTurbine = Ext.ModelMgr.create({name:"T31", id: 30, plant_id: 1}, "Turbine");
app.stores.turbines.add(firstTurbine);
app.stores.turbines.sync();
}
return {firstTurbine: firstTurbine, firstPlant: firstPlant};
}
http://stackoverflow.com/questions/6622878/(私の[モデル+組合+店舗についての答え]を読みますextjs-4-models-with-associations-and-stores/6888446#6888446)を参照してください。私はあなたに同じ問題があると思います。 –
それは非常に良い例ですが、私はそれが私の問題の解決策ではないと信じています。私が自分のデータを使ってやりたいことは、彼らが付けられている濁りとプラントのリストを作ることです。フィルタリングの問題は、一度に1つのフィルタしか表示できないことです。では、どのようにして、所属プラントのデータがあるxタービンのリストを取得できますか? – lronhoj