我通过json生成了多级select
<div ng-app="xx" ng-controller="eee">
<div>
**{{col_selectlv[1].colname}}**//这个地方下文说到!
<select ng-model="col_selectlv[0]" ng-options="x.colname for x in col_select[0]" required>
<option></option>
</select>
<select ng-model="col_selectlv[1]" ng-options="x.colname for x in col_selectlv[0].children"
ng-if="col_selectlv[0].children"
required >
<option></option>
</select>
<select ng-model="col_selectlv[2]" ng-options="x.colname for x in col_selectlv[1].children"
ng-if="col_selectlv[1].children" required >
<option></option>
</select>
<select ng-model="col_selectlv[3]" ng-options="x.colname for x in col_selectlv[2].children"
ng-if="col_selectlv[2].children" required >
<option></option>
</select>
</div>
</div>
app.js是这样的:
app.controller('newseditor', function ($scope, $http,$routeParams) {
$scope.newsid=$routeParams.id?$routeParams.id:'0';
$http({
method: 'GET',
url: 'datacon/col_select.php',
}).success(function (response) {
// console.log(response);
if (response)
$scope.col_select = response;
})
$scope.change_selecter = function (r) {
$scope.select_range = r;
}
$scope.news_submit = function () {
console.log($scope.col_selectlv)
}
});
通过点击button激活news_submit,希望的效果是能输出col_selectlv,但是输出的结果是未定义。
ng-model是绑定成功了,因为上面标注的那个{{col_selectlv[1].colname}}是可以输出的,但是不知道为什么就是不能通过$scope.col_selectlv获取。
原来是因为ng-if会创建一个子域,所以
app.controller('newseditor', function ($scope, $http,$routeParams) {