使用Json Ajax响应的Polulate Select Box

时间:2016-06-07 07:38:48

标签: jquery json ajax

我有一个从Ajax请求返回的json数组,如下所示。

WebDriverWait wait = new WeBDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("")));

我想抓取每个数据,并在选择框中选择它。但是jquery代码不起作用。谢谢你的帮助。

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.53.0</version>
</dependency>

1 个答案:

答案 0 :(得分:1)

var response = {
  "success":true,
  "message":null,
  "messages":null,
  "data":[
    {"Type":"Model","Value":"A Model"},
    {"Type":"Model","Value":"B Model"}
  ]
}

$.each(response.data, function(key, val){
   $('select').append('<option id="' + val.Value + '">' +   val.Value +'</option>');//missing +
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select></select>