次のコードがあります。
Person = new Backbone.Model({
data:[
{ age: "27" },
{name: "alamin"}
]
});
さて、どうすれば値を取得できますか?
person=new Person();
person.get(?);
解決策を教えてください。
次のコードがあります。
Person = new Backbone.Model({
data:[
{ age: "27" },
{name: "alamin"}
]
});
さて、どうすれば値を取得できますか?
person=new Person();
person.get(?);
解決策を教えてください。
モデルを定義するときのデータプロパティがわかりません-おそらくデフォルトを意味しますか?のように
var Person = Backbone.Model.extend({
defaults: {
property1: value1,
property2: value2,
property3: ["arrval1", "arrval2", "arrval3"]
});
get:myperson.get('property1')を使用して、特定のプロパティの値を取得します。プロパティの値を設定するには、set:myperson.set('property1'、'newValueOfProperty')を使用します。
プロパティが配列の場合、myperson.get('property3')[index]
配列をオブジェクトとして取得するには:
使用するperson.get('data')
配列から属性の値を取得するには、次のようにします。
使用するperson.get('data').name
または person.get('data')['name']
配列の特定の要素の属性を取得するには:
var people = person.get('data'); // This gets the array of people.
var individual = people[0]; // This gets the 0th element of the array.
var age = individual.age; // This gets the age property.
var name = individual.name; // This gets the name property.