使用$ http.get获取select的值

时间:2016-06-10 13:09:33

标签: angularjs

AngularJs(1)。我有2个HTML选择。每个select都使用ajax调用($ http.get)

中的值

第一:

<option ng-repeat="lab in getLabels('A')" value="{{lab}}">{{lab}}</option>

第二:

<option ng-repeat="lab in getLabels('X')" value="{{lab}}">{{lab}}</option>

问题是因为ajax,getLabels返回一个promise,而不是一个直接列表。如何解决这个问题,知道我必须为2个选项中的每一个使用特定参数

这是 my test pen (我使用&#34; $ q&#34;服务模拟ajax调用)

1 个答案:

答案 0 :(得分:1)

不要直接绑定。使用调解员:(更新!) 像这样的Smth

"""
Reload servers from a list of IPs

This script looks for a server with a determinate IP address and reload it from an image template.

Important manual pages:
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware_Server
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/findByIpAddress
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/reloadOperatingSystem

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""

import SoftLayer
import json

ipsToReload = ['184.172.45.215', '1.1.1.1']

# Call the Softlayer_Account::getPrivateBlockDeviceTemplateGroups method.
# to get the images templates in the account.
imageTemplateId = 51236

USERNAME = 'set me'
API_KEY = 'set me'

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
hardwareService = client['SoftLayer_Hardware_Server']


failedServers = []
for ipToReload in ipsToReload:
    failedServer = {}
    failedServer['ip'] = ipToReload
    try:
        server = hardwareService.findByIpAddress(ipToReload)
        if server == '':
            failedServer['error'] = "Ip does not exist."
            failedServers.append(failedServer)
            continue
    except SoftLayer.SoftLayerAPIError as e:
        failedServer['error'] = e
        failedServers.append(failedServer)
        continue
    if 'activeTransaction' in server:
        failedServer['error'] = "There is an active transaction."
        failedServers.append(failedServer)
        continue

    config = {
        'imageTemplateId': imageTemplateId
    }

    try:
        reload = hardwareService.reloadOperatingSystem('FORCE', config, id=server['id'])
    except SoftLayer.SoftLayerAPIError as e:
        failedServer['error'] = e
        failedServers.append(failedServer)
        continue

print("The reload failed for these IPs:")
print(json.dumps(failedServers, sort_keys=True, indent=2, separators=(',', ': ')))
相关问题