使用Angularjs从JSON获取领域

编程入门 行业动态 更新时间:2024-10-11 15:15:14
本文介绍了使用Angularjs从JSON获取领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是一个很简单的问题,但我正在写的应该显示用户的信息的网页。将有姓名,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获取领域

本文发布于:2023-11-26 08:48:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633436.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:领域   Angularjs   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!