使用Angularjs从JSON获取领域 [英] Getting fields from JSON using Angularjs
问题描述
这是一个很简单的问题,但我正在写的应该显示用户的信息的网页。将有姓名,ID,角色等领域我想写的,我从数据库中获得JSON setter和getter方法。例如,如果我得到一个JSON,我想获取和显示名称字段中,我如何写angularJS此getter方法从$资源服务得到JSON之后?
This is a very simple question but I'm writing a webpage that's supposed to display the user's information. There will be fields of name, id, role, etc. I want to write setter and getter methods for the JSON that I receive from the database. For example, if I get a JSON and I want to get and display the name field, how would I write this getter method in angularJS after getting the JSON from a $resource service?
这是的JSON会怎样看一个例子:
This is an example of how the JSON would look:
[{"name": "Jason"
"date of birth": "february 23, 2985"
....
}]
同样,我只是想知道如何写一个getter方法,如果我想获得的名称字段。
Again, I just want to know how to write a getter method if I wanted to get the name field.
推荐答案
应该是一样的JavaScript。
Should be just like javascript.
var result = [{"name": "Jason"
"date of birth": "february 23, 2985"
....
}];
var firstResultsName = result[0].name;
但我注意到,你给结果的问题。你需要一个逗号分隔每个属性之后。
But i noticed a problem with the result that you gave. You need a comma after each property.
[{"name": "Jason", <<-- this comma is necessary to work correctly.
"date of birth": "february 23, 2985", <<-- and this one.
请确保您有逗号为所有,但最后一个属性。
make sure you have commas for all but the last property.
这篇关于使用Angularjs从JSON获取领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!