Using angular to introduce complex JSON files

Source: Internet
Author: User

We have a lot of repeating code and repeating styles when we write our web pages, and we can't knock them out of the way, so it's a manual work.

So when I was in this situation, most of the time I used angular to get JSON, and using angular to import the data from the JSON database into a Web page would allow us to write duplicate code without repeating it.

But some sub-elements are relatively good, but like a drop-down list is more troublesome. Not only is it cumbersome to write JSON files, it's even more complicated to get JSON.

For example, when we're writing a JSON file like this,

"Recruit": [
{"Name": "1", "describe": [
{"Descr": "2"},
{"Descr": "3"},
{"Descr": "4"},
{"Descr": "5"},
{"DESCR": "6"}
],

"Describe1": [
{"DESCR": "11"},
{"DESCR": "22"},
{"DESCR": "33"},
{"DESCR": "44"},
{"Descr": "55"},
{"DESCR": "66"}
]}
]

This JSON file is believed to have been seen, and this JSON is not as simple as what we get when it comes to a single JSON, and we use "subscript" to get the data we want when we get it.

App.controller (' Test ', function ($scope, $http) {
$http. Get ('.. /data/data.json '). Success (function (data) {
$scope. Data = Data.recruit;
$scope. Headernav = $scope. Data[0].name;
$scope. headerNav1 = $scope. Data[1].describe;

$scope. headerNav1 = $scope. DATA[2].DESCRIBE1;

}). Error (function (s) {
alert (s);
})
})

So we can get the data we want and write it to the page.

Using angular to introduce complex JSON files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.