gpt4 book ai didi

javascript - 双击 Angular-JS ajax

转载 作者:行者123 更新时间:2023-12-03 08:37:48 26 4
gpt4 key购买 nike

我正在尝试检索第一个选定的值,然后运行 ​​ajax 调用以根据第一个选定的值获取第二组数据。

HTML:

<label class="item item-input item-select">
<div class="input-label">
Select First:
</div>

<select>
<option ng-repeat="object in objects" value="object.ID">{{object.value}}</option>
</select>
</label>

<label class="item item-input item-select">
<div class="input-label">
Select 2nd:
</div>

<select>
<option></option>
</select>
</label>

Controller 端:

...
dataFactory.getRequestObject(ID).then(function(resp2){
console.log("Getting data to populate select list!");
console.log(resp2.data);
$scope.objects= resp2.data;

}, function(err){
console.error('ERROR', err);
});

其中 getRequestObject(ID) 是调用我的网络服务的函数。

我能够获取第一组数据,我想获取第一组数据的“值”并调用第二组数据选择列表的检索。我该如何去做呢?

最佳答案

$.getJson(url, param, function(data) {
$scope.array1 = data.array;
});
$scope.onchange = function() {
//ng-model will store its value into $scope
var selectValue1 = $scope.selectValue1;

$.getJson(url2, param2, function(data) {
$scope.array2 = data.array;
});
};
<select ng-module="selectValue1" ng-options="label for value in array1" ng-change="onchange()"></select>
<select ng-module="selectValue2" ng-options="label for value in array2"></select>

使用 $watch 检测 selectValue 变化也可以工作

关于javascript - 双击 Angular-JS ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33143560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com