zoukankan      html  css  js  c++  java
  • angular.js 下拉框选中 根据后台返回值

    前景,根据后台返回值选中某个项

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
    </head>
    <body>
    <div ng-app="myApp" ng-controller="myCtrl">
    <select ng-init="selectedName = namess" ng-model="selectedName" ng-options="x for x in names">

    </select>
    </div>
    <script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
    // Runoob 假如后台要我们选中 Runoob
    $scope.names = ["Google", "Runoob", "Taobao"];
    for(var i = 0; i<$scope.names.length;i++){
    if ($scope.names[i] == 'Taobao'){
    $scope.namess = $scope.names[i] //让其初始化选中这个
    }
    }
    });
    </script>
    //适合一个下拉列表的情况下,如果有多个遍历循环是思路一样
    </body>
    </html>
  • 相关阅读:
    异步编程
    MVC返回文件
    MVC源码分析
    MVC源码分析
    MVC源码分析
    MVC源码分析
    MVC源码分析
    MVC源码分析
    MVC源码分析
    MVC源码分析
  • 原文地址:https://www.cnblogs.com/zou1234/p/7777390.html
Copyright © 2011-2022 走看看