angular.js - AngularJs 級聯
黄舟
黄舟 2017-05-15 16:54:06
0
1
667

Angular.js 的版本是1.2.5
要實現的功能是 Select 三級連動。
出現的問題是:選擇完第二級(國家)的時候,第三級(城市)沒有出現。
請大俠們指導!

-- HTML程式碼 --

<p ng-app="app" ng-controller="global">
    <select ng-model="ihg" ng-options="ihg.text for ihg in g">
        <option value="">-- 洲际 --</option>
    </select>
    <select ng-if="ihg.nat" ng-model="nat" ng-options="nat.text for nat in ihg.nat">
        <option value="">-- 国家 --</option>
    </select>
    <select ng-if="nat.cities" ng-model="city" ng-options="city.text for city in nat.cities">
        <option value="">-- 城市 --</option>
    </select>
</p>

-- JS代碼 --

var app=angular.module("app",[]);
app.controller("global",['$scope',function($scope){
    $scope.g=[
        {text:"亚洲",nat:[
            {text:"中国",cities:[{text:"北京"}]},
            {text:"巴林",cities:[]},
            {text:"韩国",cities:[{text:"首尔"}]},
            {text:"黎巴嫩",cities:[]},
            {text:"东帝汶",cities:[]},
            {text:"尼泊尔",cities:[]},
            {text:"泰国",cities:[{text:"曼谷"}]},
            {text:"巴基斯坦",cities:[{text:"伊斯兰堡"}]}
        ]},
        {text:"欧洲",nat:[
            {text:"德国",cities:[]},
            {text:"英国",cities:[]}
        ]},
        {text:"北美洲"},
        {text:"南美洲"},
        {text:"非洲"},
        {text:"大洋洲"},
        {text:"南极洲"}
    ]
}]);
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回覆(1)
为情所困

ng-if改為ng-show

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!