1
私はExtJSを初めて使う人です。
このコードが動作しない理由はわかりません。
それはここでは、コードである私にエクステンションの学習、参考エラーの問題
ReferenceError: Country is not defined
を与える:
Ext.define("Continent", {
extend: "Ext.data.Model",
fields: ["name"]
});
Ext.define("City", {
extend: "Ext.data.Model",
fields: ["name"]
});
Ext.define("CountryDetails", {
extend: "Ext.data.Model",
fields: ["id","population"],
});
Ext.define("Country", {
extend: "Ext.data.Model",
idProperty : "name",
fields: ["name", "capital"],
hasMany: [{ name: "cities", model: "City"}],
hasOne: [{model:"CountryDetails"}],
belongsTo: [{ model: "Continent"}],
proxy : {
type : "memory",
data : {
country : {
name : "France",
capital : "Paris",
countrydetails : {
id : "cd101",
population : 65436552
},
cities : [{name:"Lyon"},{name:"Avignon"}],
continent : {
name : "Europe"
}
}
},
reader : {
type : "json",
root : "country"
}
}
});
Country.load("France",{
success : function(record){
var continent = record.getContinent();
console.log(continent.get("name"));
var countryDetails = record.getCountryDetails();
console.log(countryDetails.get("population"));
var cities = record.cities();
cities.each(function(city){
console.log(city.get("name"));
});
}
});
私は実用的ExtJSの4ブックからコピーされ、それが動作しません...私はと満足していませんあなたのコードが完璧に働いている
'var Country = Ext.create( 'Country');'のような行が見つからないと思います。 'Ext.define'は「クラス」を定義し、「Ext.create」はインスタンスを作成します。 – Alexander
@Alexander試しましたが、それは私に多くのエラーを与えました。それは、モデルだけでうまくいくはずです。私は、作成者が.create()のような明白なものを見逃さないと思います。 – alexandre1985
コードはExt 4.xで期待通りに動作します。あなたは[fiddle](http://fiddle.sencha.com)でエラーを試してみてください。 – Emissary