angularjs---select使用---預設值及聯動

來源:互聯網
上載者:User

標籤:

 

 

 

 

 

代碼

 

一. select設定預設顯示內容&&擷取下拉框顯示內容.HTML<div>  <select ng-model="current_option" ng-options="option.key for option in option_array"> </select></div>JS$(function() {    /**** 設定下拉框顯示內容 ****/    $scope.option_array = [        {"key" : "hello", "value" : 1},        {"key" : "world", "value" : 2},    ];    $scope.current_option = $scope.option_array[0];  // 下拉框預設顯示內容        console.log($scope.current_option.key);              // 擷取下拉框顯示內容     console.log($scope.current_option.value);         // 擷取下拉框顯示內容對應的值})二. select二級聯動.HTML<div>  <select ng-model="current_option" ng-options="option.key for option in option_array" ng-change="current_option_change()"> </select></div><div>  <select ng-model="child_current_option" ng-options="option.key for option in child_option_array"> </select></div>JS$(function()   // 這是動作, 立即執行{    /**** 設定父下拉框顯示內容 ****/    $scope.option_array = [        {"key" : "hello", "value" : 2},        {"key" : "world", "value" : 2},    ];    $scope.current_option = $scope.option_array[0];          // 父下拉框預設顯示內容        /**** 初始載入時根據父下拉框內容顯示子下拉框內容 ****/    $scope.child_change_with_father();})/**** 根據父下拉框當前顯示內容設定子下拉框內容 ****/$scope.child_change_with_father = function ()                        // 這是方法, 調用執行{    if ("hello" == $scope.current_option.key)     {        $scope.child_option_array = [            {"key" : "hello_child_one", "value" : 1},            {"key" : "hello_child_two", "value" : 2},        ];    }    else if ("world" == $scope.current_option.key)    {        $scope.child_option_array = [            {"key" : "world_child_one", "value" : 3},            {"key" : "world_child_two", "value" : 4},        ];    }    $scope.child_current_option = $scope.child_option_array[0];  // 子下拉框預設顯示內容}$scope.current_option_change = function() {    $scope.child_change_with_father();}

 

angularjs---select使用---預設值及聯動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.