如何从Backbone.js的模型中获取数组元素 [英] how to get array element from model in backbone.js

查看:257
本文介绍了如何从Backbone.js的模型中获取数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code。

Person = new Backbone.Model({

 data:[
    { age: "27" },
    {name: "alamin"}
]

});

现在,我怎么能获得的价值?

now , how can i get the value?

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

请告诉我的解决方案。

推荐答案

定义模型的时候,我不知道一个数据属性的 - 也许你的意思是默认?在

I don't know of a data property when defining a model - maybe you mean defaults? as in

var Person = Backbone.Model.extend({
   defaults: {
      property1: value1,
      property2: value2,
      property3: ["arrval1", "arrval2", "arrval3"]
   });

您会使用 GET 检索某些属性的值:myperson.get('property1') 。
要设置属性使用设置的值:myperson.set('property1','newValueOfProperty')

You would retrieve the value of certain property using get: myperson.get('property1'). To set the value of a property use set: myperson.set('property1', 'newValueOfProperty')

如果一个属性是一个数组的myperson.get('property3')[指数]

If a property is an array the myperson.get('property3')[ index ]

这篇关于如何从Backbone.js的模型中获取数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆