骨干从嵌套json中获取数据
Backbone getting data from nested json
我的Json数组如下如何使用Backbone提取Name和temp
{
"message": "accurate",
"cod": "200",
"count": 10,
"list": [
{
"id": 495260,
"name": "Shcherbinka",
"coord": {
"lon": 37.559719,
"lat": 55.499722
},
"main": {
"temp": 274.72,
"pressure": 1033,
"humidity": 93,
"temp_min": 272.04,
"temp_max": 277.04
},
"dt": 1444968405,
"wind": {
"speed": 2,
"deg": 300
},
"sys": {
"country": ""
},
"clouds": {
"all": 76
},
"weather": [
{
"id": 803,
"main": "Clouds",
"description": "broken clouds",
"icon": "04d"
}
]
},
我的JavaScript代码如下:
<script>
$(function() {
var Profile = Backbone.Model.extend();
var ProfileList = Backbone.Collection.extend({
model: Profile,
url: "http://api.openweathermap.org/data/2.5/find?lat=55.5&lon=37.5&cnt=10&appid=bd82977b86bf27fb59a04b61b657fb6f",
parse : function(response){
weather_data = response.list
console.log(weather_data)
return weather_data;
}
});
var ProfileView = Backbone.View.extend({
el: "#profiles",
template: _.template($('#profileTemplate').html()),
render: function(eventName) {
_.each(this.model.models, function(profile){
var profileTemplate = this.template(profile.toJSON());
$(this.el).append(profileTemplate);
}, this);
return this;
}
});
var profiles = new ProfileList();
profiles.fetch();
var profilesView = new ProfileView({model: profiles});
profiles.fetch({
success: function() {
profilesView.render();
}
});
});
</script>
如何从上面的Json中获得Name
和temperature
,它们在Json对象中的不同Json对象
by
如何从上面的Json获取名称和温度
如果你想访问'name'和'temp',你可以这样访问它们,一旦它们在模型中设置。
model.get("name"); //"Shcherbinka"
model.get("main").temp; //274.72
相关文章:
- Ajax-如何获取数据
- 从键值结构中获取数据,并将其与AngularJS中ng重复的值进行比较
- 从数据库中获取数据并插入JavaScript变量
- 从单击的行上的列中获取数据
- Solr查询以按日期月份获取数据&年
- React路由器服务器端渲染和ajax获取数据
- 使用JavaScript在IE9中获取数据列表选项
- 从json子数组获取数据
- 使用angularjs中的rest调用通过id获取数据
- 正在从ruby应用程序中的数据库中获取数据
- 如何从servlet获取数据到ajax成功
- 从选择下拉菜单中获取数据
- 异步获取数据使用JavaScript同步获取数据
- 从服务器获取数据并在选择控件中使用ng选项无法显示选项
- 如何在Angular.js中循环动态添加Fields并获取数据并将其发送到服务器
- JavaScript-获取数据属性的值返回未定义的值
- 如何从文本区域获取数据并使用javascript进行解密
- 在put方法之前从作用域获取数据
- 事件循环的MEAN.JS setInterval进程(从另一个服务器获取数据)
- 使用ReactJS和Flux架构从服务器获取数据的正确方法是什么