0

我有 2 个使用填充的选择表单ng-options,例如:

<select ng-options="item.id as product.category for product in products" ng-model="order.category" ng-change='find_brands(order.category)' ></select>
<select ng-options="brand.id as brand.name for brand in brands" ng-model="order.brand" ></select>
<button ng-click='Get_Products(order)>ORDER</button>

选择第一个下拉列表时,它将触发$http填充第二个下拉列表的调用,如下所示:

$scope.find_brands = function(category){
  $http
    .get('Default.aspx/Find_Brands', {category: category})
    .success(data){$scope.products = data.d};
};

"brands"这会使用新值正确填充下拉列表。但是,当我去选择一个品牌时,它ng-model并没有改变。测试时,我收到一个空值。我已经考虑过$scope.$apply使用这个$digest循环,但这似乎不是我的问题("brands"下拉列表成功获取刷新的数据,它只是不发送数据)。

有谁知道发生了什么以及如何解决它?

4

1 回答 1

1

我一直在为您创建这个简单的示例:http: //jsbin.com/degece/edit ?html,js,console,output

在您的代码中存在一些错误。

在这一行中,您使用 item.id 而不是 product.id

<select ng-options="item.id as product.category for product in products" ng-model="order.category" ng-change='find_brands(order.category)' ></select>

在这你有一个报价错字,你不需要 Get_Products 之前的报价

<button ng-click='Get_Products(order)>ORDER</button>

最后,这里需要将调用结果赋给 $scope.brands变量

.success(data){$scope.products = data.d};

在我的示例中,您可以看到一些最佳实践实现,例如模型初始化。

于 2016-02-26T21:23:19.427 回答