如何制作带有子项的AngularJs ng选项
我想将json返回的登录名放入ng选项中。 问题是登录名和其他属性(如id、url等)作为的子项 如何使用其值创建一个角度选项 Html如何制作带有子项的AngularJs ng选项,angularjs,json,angularjs-ng-options,subitem,Angularjs,Json,Angularjs Ng Options,Subitem,我想将json返回的登录名放入ng选项中。 问题是登录名和其他属性(如id、url等)作为的子项 如何使用其值创建一个角度选项 Html <html ng-app="myapp"> <head> ... </head> <body ng-controller="MainController"> <select ng-options="l as list.items.login for l in lists"
<html ng-app="myapp">
<head>
...
</head>
<body ng-controller="MainController">
<select ng-options="l as list.items.login for l in lists"
ng-model="item" ng-change="update()"></select>
... </html>
我
返回的Json
{
"total_count": 4,
"incomplete_results": false,
"items": [
{
"login": "mojombo",
"id": 1,
"avatar_url": "https://avatars3.githubusercontent.com/u/1?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/mojombo",
"html_url": "https://github.com/mojombo",
"followers_url": "https://api.github.com/users/mojombo/followers",
"following_url": "https://api.github.com/users/mojombo/following{/other_user}",
"gists_url": "https://api.github.com/users/mojombo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mojombo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mojombo/subscriptions",
"organizations_url": "https://api.github.com/users/mojombo/orgs",
"repos_url": "https://api.github.com/users/mojombo/repos",
"events_url": "https://api.github.com/users/mojombo/events{/privacy}",
"received_events_url": "https://api.github.com/users/mojombo/received_events",
"type": "User",
"site_admin": false,
"score": 49.54566
},
{
"login": "tomdale",
"id": 90888,
"avatar_url": "https://avatars1.githubusercontent.com/u/90888?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/tomdale",
"html_url": "https://github.com/tomdale",
"followers_url": "https://api.github.com/users/tomdale/followers",
"following_url": "https://api.github.com/users/tomdale/following{/other_user}",
"gists_url": "https://api.github.com/users/tomdale/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tomdale/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tomdale/subscriptions",
"organizations_url": "https://api.github.com/users/tomdale/orgs",
"repos_url": "https://api.github.com/users/tomdale/repos",
"events_url": "https://api.github.com/users/tomdale/events{/privacy}",
"received_events_url": "https://api.github.com/users/tomdale/received_events",
"type": "User",
"site_admin": false,
"score": 40.39779
},
{
"login": "tmcw",
"id": 32314,
"avatar_url": "https://avatars1.githubusercontent.com/u/32314?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/tmcw",
"html_url": "https://github.com/tmcw",
"followers_url": "https://api.github.com/users/tmcw/followers",
"following_url": "https://api.github.com/users/tmcw/following{/other_user}",
"gists_url": "https://api.github.com/users/tmcw/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tmcw/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tmcw/subscriptions",
"organizations_url": "https://api.github.com/users/tmcw/orgs",
"repos_url": "https://api.github.com/users/tmcw/repos",
"events_url": "https://api.github.com/users/tmcw/events{/privacy}",
"received_events_url": "https://api.github.com/users/tmcw/received_events",
"type": "User",
"site_admin": false,
"score": 36.811348
},
{
"login": "tommy351",
"id": 411425,
"avatar_url": "https://avatars3.githubusercontent.com/u/411425?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/tommy351",
"html_url": "https://github.com/tommy351",
"followers_url": "https://api.github.com/users/tommy351/followers",
"following_url": "https://api.github.com/users/tommy351/following{/other_user}",
"gists_url": "https://api.github.com/users/tommy351/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tommy351/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tommy351/subscriptions",
"organizations_url": "https://api.github.com/users/tommy351/orgs",
"repos_url": "https://api.github.com/users/tommy351/repos",
"events_url": "https://api.github.com/users/tommy351/events{/privacy}",
"received_events_url": "https://api.github.com/users/tommy351/received_events",
"type": "User",
"site_admin": false,
"score": 15.513104
}
]
}
试试这个,你可以根据登录名选择项目
var-app=angular.module('myApp',[]);
应用程序控制器('myCrtl',功能($scope){
$scope.data={
“总计数”:4,
“结果不完整”:错误,
“项目”:[
{
“登录”:“mojombo”,
“id”:1,
“头像url”:https://avatars3.githubusercontent.com/u/1?v=3",
“gravatar_id”:“,
“url”:”https://api.github.com/users/mojombo",
“html_url”:”https://github.com/mojombo",
“关注者url”:https://api.github.com/users/mojombo/followers",
“以下url:”https://api.github.com/users/mojombo/following{/other_user}“,
“gists_url”:https://api.github.com/users/mojombo/gists{/gist_id}“,
“带星号的url”:https://api.github.com/users/mojombo/starred{/owner}{/repo}“,
“订阅\u url”:https://api.github.com/users/mojombo/subscriptions",
“组织\u url”:https://api.github.com/users/mojombo/orgs",
“repos_url”:https://api.github.com/users/mojombo/repos",
“事件\u url”:https://api.github.com/users/mojombo/events{/隐私}“,
“收到的\u事件\u url”:https://api.github.com/users/mojombo/received_events",
“类型”:“用户”,
“站点管理”:false,
“分数”:49.54566
},
{
“登录”:“tomdale”,
“id”:90888,
“头像url”:https://avatars1.githubusercontent.com/u/90888?v=3",
“gravatar_id”:“,
“url”:”https://api.github.com/users/tomdale",
“html_url”:”https://github.com/tomdale",
“关注者url”:https://api.github.com/users/tomdale/followers",
“以下url:”https://api.github.com/users/tomdale/following{/other_user}“,
“gists_url”:https://api.github.com/users/tomdale/gists{/gist_id}“,
“带星号的url”:https://api.github.com/users/tomdale/starred{/owner}{/repo}“,
“订阅\u url”:https://api.github.com/users/tomdale/subscriptions",
“组织\u url”:https://api.github.com/users/tomdale/orgs",
“repos_url”:https://api.github.com/users/tomdale/repos",
“事件\u url”:https://api.github.com/users/tomdale/events{/隐私}“,
“收到的\u事件\u url”:https://api.github.com/users/tomdale/received_events",
“类型”:“用户”,
“站点管理”:false,
“分数”:40.39779
},
{
“登录”:“tmcw”,
“id”:32314,
“头像url”:https://avatars1.githubusercontent.com/u/32314?v=3",
“gravatar_id”:“,
“url”:”https://api.github.com/users/tmcw",
“html_url”:”https://github.com/tmcw",
“关注者url”:https://api.github.com/users/tmcw/followers",
“以下url:”https://api.github.com/users/tmcw/following{/other_user}“,
“gists_url”:https://api.github.com/users/tmcw/gists{/gist_id}“,
“带星号的url”:https://api.github.com/users/tmcw/starred{/owner}{/repo}“,
“订阅\u url”:https://api.github.com/users/tmcw/subscriptions",
“组织\u url”:https://api.github.com/users/tmcw/orgs",
“repos_url”:https://api.github.com/users/tmcw/repos",
“事件\u url”:https://api.github.com/users/tmcw/events{/隐私}“,
“收到的\u事件\u url”:https://api.github.com/users/tmcw/received_events",
“类型”:“用户”,
“站点管理”:false,
“分数”:36.811348
},
{
“登录”:“tommy351”,
“id”:411425,
“头像url”:https://avatars3.githubusercontent.com/u/411425?v=3",
“gravatar_id”:“,
“url”:”https://api.github.com/users/tommy351",
“html_url”:”https://github.com/tommy351",
“关注者url”:https://api.github.com/users/tommy351/followers",
“以下url:”https://api.github.com/users/tommy351/following{/other_user}“,
“gists_url”:https://api.github.com/users/tommy351/gists{/gist_id}“,
“带星号的url”:https://api.github.com/users/tommy351/starred{/owner}{/repo}“,
“订阅\u url”:https://api.github.com/users/tommy351/subscriptions",
“组织\u url”:https://api.github.com/users/tommy351/orgs",
“repos_url”:https://api.github.com/users/tommy351/repos",
“事件\u url”:https://api.github.com/users/tommy351/events{/隐私}“,
“收到的\u事件\u url”:https://api.github.com/users/tommy351/received_events",
“类型”:“用户”,
“站点管理”:false,
“分数”:15.513104
}
]
}
});代码>
所选项目:{{selectedItem}
试试这个,你可以根据登录名选择项目
var-app=angular.module('myApp',[]);
应用程序控制器('myCrtl',功能($scope){
$scope.data={
“总计数”:4,
“结果不完整”:错误,
“项目”:[
{
“登录”:“mojombo”,
“id”:1,
“头像url”:https://avatars3.githubusercontent.com/u/1?v=3",
“gravatar_id”:“,
“url”:”https://api.github.com/users/mojombo",
“html_url”:”https://github.com/mojombo",
“关注者url”:https://api.github.com/users/mojombo/followers",
“以下url:”https://api.github.com/users/mojombo/following{/other_user}“,
“gists_url”:https://api.github.com/users/mojombo/gists{/gist_id}“,
“带星号的url”:https://api.github.com/users/mojombo/starred{/owner}{/repo}“,
“订阅\u url”:https://api.github.com/users/mojombo/subscriptions",
“组织\u url”:https://api.github.com/user
{
"total_count": 4,
"incomplete_results": false,
"items": [
{
"login": "mojombo",
"id": 1,
"avatar_url": "https://avatars3.githubusercontent.com/u/1?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/mojombo",
"html_url": "https://github.com/mojombo",
"followers_url": "https://api.github.com/users/mojombo/followers",
"following_url": "https://api.github.com/users/mojombo/following{/other_user}",
"gists_url": "https://api.github.com/users/mojombo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mojombo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mojombo/subscriptions",
"organizations_url": "https://api.github.com/users/mojombo/orgs",
"repos_url": "https://api.github.com/users/mojombo/repos",
"events_url": "https://api.github.com/users/mojombo/events{/privacy}",
"received_events_url": "https://api.github.com/users/mojombo/received_events",
"type": "User",
"site_admin": false,
"score": 49.54566
},
{
"login": "tomdale",
"id": 90888,
"avatar_url": "https://avatars1.githubusercontent.com/u/90888?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/tomdale",
"html_url": "https://github.com/tomdale",
"followers_url": "https://api.github.com/users/tomdale/followers",
"following_url": "https://api.github.com/users/tomdale/following{/other_user}",
"gists_url": "https://api.github.com/users/tomdale/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tomdale/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tomdale/subscriptions",
"organizations_url": "https://api.github.com/users/tomdale/orgs",
"repos_url": "https://api.github.com/users/tomdale/repos",
"events_url": "https://api.github.com/users/tomdale/events{/privacy}",
"received_events_url": "https://api.github.com/users/tomdale/received_events",
"type": "User",
"site_admin": false,
"score": 40.39779
},
{
"login": "tmcw",
"id": 32314,
"avatar_url": "https://avatars1.githubusercontent.com/u/32314?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/tmcw",
"html_url": "https://github.com/tmcw",
"followers_url": "https://api.github.com/users/tmcw/followers",
"following_url": "https://api.github.com/users/tmcw/following{/other_user}",
"gists_url": "https://api.github.com/users/tmcw/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tmcw/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tmcw/subscriptions",
"organizations_url": "https://api.github.com/users/tmcw/orgs",
"repos_url": "https://api.github.com/users/tmcw/repos",
"events_url": "https://api.github.com/users/tmcw/events{/privacy}",
"received_events_url": "https://api.github.com/users/tmcw/received_events",
"type": "User",
"site_admin": false,
"score": 36.811348
},
{
"login": "tommy351",
"id": 411425,
"avatar_url": "https://avatars3.githubusercontent.com/u/411425?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/tommy351",
"html_url": "https://github.com/tommy351",
"followers_url": "https://api.github.com/users/tommy351/followers",
"following_url": "https://api.github.com/users/tommy351/following{/other_user}",
"gists_url": "https://api.github.com/users/tommy351/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tommy351/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tommy351/subscriptions",
"organizations_url": "https://api.github.com/users/tommy351/orgs",
"repos_url": "https://api.github.com/users/tommy351/repos",
"events_url": "https://api.github.com/users/tommy351/events{/privacy}",
"received_events_url": "https://api.github.com/users/tommy351/received_events",
"type": "User",
"site_admin": false,
"score": 15.513104
}
]
}