[英]Passing an array of check-boxes with ajax using angular js
我需要執行一個ajax GET請求,提交一個復選框數組(都具有相同的名稱):例如:
類型[] =新
type [] =已使用
type [] =翻新
這是我嘗試訪問的API所必需的。 但是我不確定如何實現這一目標。
除了這些復選框,我還有其他所有與API一起使用的功能。
這是定義復選框的方式:
self.types = ['new', 'used', 'refurbished'];
//....
<label ng-repeat="type in search.types">
<input
type="checkbox"
name="type[]"
value="{{type}}"
> {{type}}
</label>
這就是我添加要發送到API的值的方式,例如:
dataObj['price'] = $scope.formData.max_price;
//need to do similar as this for the type[] checkboxes
然后將它們發送到API:
return $http({
url: APIUrl + "search/",
method: "GET",
params: dataObj
});
//etc
因此,發布到API的參數必須看起來像:
price = 400000
type[] = new
type[] = refurbished
//NB: "used" wasn't submitted as the "used" checkbox wasn't checked
^這不靈活,API要求這樣做。
非常感謝
使用ng-model =“ checkbox1”,ng-model =“ checkbox2”,ng-model =“ checkbox3”並將它們收集到對象中。
數據= {價格:價格,類型1:復選框1,類型2:復選框2,類型3:復選框3}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.