我透過json產生了多層select
<code><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></code>
app.js是這樣的:
<code> 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) } });</code>
透過點擊button啟動news_submit,希望的效果是能輸出col_selectlv,但是輸出的結果是未定義。
ng-model是綁定成功了,因為上面標註的那個{{col_selectlv[1].colname}}是可以輸出的,但是不知道為什麼就是不能透過$scope.col_selectlv來取得。
我透過json產生了多層select
<code><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></code>
app.js是這樣的:
<code> 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) } });</code>
透過點擊button啟動news_submit,希望的效果是能輸出col_selectlv,但是輸出的結果是未定義。
ng-model是綁定成功了,因為上面標註的那個{{col_selectlv[1].colname}}是可以輸出的,但是不知道為什麼就是不能透過$scope.col_selectlv來取得。
你的控制器名字是eee還是newseditor,程式碼好像不完整
原來是因為ng-if會創建一個子域,所以
app.controller('newseditor', function ($scope, $http,$routeParams) {
<code> **$scope.col_selectlv={}** $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) } </code>
<code> }); 要定义一个$scope.col_selectlv,才能够获取到col_selectlv</code>