如何使用角度js在下拉列表中填充json数据

时间:2017-01-17 11:06:35

标签: html angularjs json

我的HTML代码是

<body ng-app="mainApp">
<div ng-controller="myController">
<select>
    <option ng-repeat="person in persons">{{ person.data }}</option>
</select>
</div>
</body>

我的js代码是

var app=angular.module("mainApp",[]); 
  app.controller("myController",function ($scope,$http){
     $http.get("my url")
     .success(function(response){
        $scope.persons=response;
   });
});

我的json代码是:

data:["bank1","bank2",bank3"]

它在一行中获取所有数据..如何在下拉框中获取?我希望数据作为列表下拉。

欢迎任何人提供帮助,谢谢。

2 个答案:

答案 0 :(得分:0)

试试这个

<select ng-model="SelectedPerson" ng-options="person for person in persons.data"></select>

更新:

Working Demo

答案 1 :(得分:0)

这应该有用。

typedef unsigned long ulong;
#define serialised_long(x)   serialised_ulong((ulong) x)
#define serialised_ulong(x)    (x & 0xFF000000) / 0x1000000 \
                             , (x & 0xFF0000)   / 0x10000   \
                             , (x & 0xFF00)     / 0x100     \
                             , (x & 0xFF)

typedef unsigned char uchar;
#define deserialised_long(x) (x[3] <= 0x7f \
                                    ? deserialised_ulong(x) \
                                    : -(long)deserialised_ulong((uchar[]) { 0x100  - x[0] \
                                                                          , 0xFF   - x[1] \
                                                                          , 0xFF   - x[2] \
                                                                          , 0xFF   - x[3] })
#define deserialised_ulong(x) ( x[0] * 0x1000000UL \
                              + x[1] * 0x10000UL   \
                              + x[2] * 0x100UL     \
                              + x[3]               )

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    FILE *f = fopen("test_output", "wb+");
    if (f == NULL)
    {
        fprintf(stderr, "Could not create %s.\n", "test_output");
        return 1;
    }

    ulong value = 0xABCDEF;
    unsigned char datagram[] = { serialised_ulong(value) };
    fwrite(datagram, sizeof datagram, 1, f);
    printf("%08lX serialised to %02X%02X%02X%02X\n", value, datagram[0], datagram[1], datagram[2], datagram[3]);

    rewind(f);

    fread(datagram, sizeof datagram, 1, f);
    value = deserialised_ulong(datagram);
    printf("%02X%02X%02X%02X deserialised to %08lX\n", datagram[0], datagram[1], datagram[2], datagram[3], value);

    fclose(f);
    return 0;
}