3

次のコードがあります。

Person = new Backbone.Model({
 data:[
    { age: "27" },
    {name: "alamin"}
]
});

さて、どうすれば値を取得できますか?

person=new Person();
person.get(?);

解決策を教えてください。

4

4 に答える 4

1

モデルを定義するときのデータプロパティがわかりません-おそらくデフォルトを意味しますか?のように

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]

于 2012-07-17T11:52:35.713 に答える
0

配列をオブジェクトとして取得するには:

使用するperson.get('data')

配列から属性の値を取得するには、次のようにします。

使用するperson.get('data').name

または person.get('data')['name']

于 2012-07-17T11:48:11.223 に答える
0

配列の特定の要素の属性を取得するには:

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.
于 2013-11-21T22:36:35.837 に答える