ui选择范围模型值中的选择框数组未正确显示

Posted

技术标签:

【中文标题】ui选择范围模型值中的选择框数组未正确显示【英文标题】:Ui select select box array in scope model value not displaying properly 【发布时间】:2019-07-01 04:18:56 【问题描述】:

对不起我的英语。 我正在使用 UI-Select 选择框来查看数据,但我正在使用 ng-model 打印数据,值抛出未定义。我正在使用基本数组。

【问题讨论】:

以下链接检查,这是我的示例plnkr.co/edit/sQ50FJVaw0flrLJFzUD3?p=preview 请编辑您的问题并在此处发布您的代码。 请尝试以下链接plnkr.co/edit/xFGkdH2nmosLec5Gd0QH?p=preview 【参考方案1】:

可以通过初始化控制器中的对象并更新该对象的属性而不是直接更新范围变量来解决此问题。

请访问link了解更多信息。

以下是解决方案的工作示例。

'use strict';

var app = angular.module('demo', ['ngSanitize', 'ui.select']);

app.controller('DemoCtrl', function($scope, $http, $timeout, $interval) 
  $scope.karthi = [1, 2, 3, 4, 5, 6, 10];
  $scope.ctrl = ;
);
<!DOCTYPE html>
<html lang="en" ng-app="demo">

<head>
  <meta charset="utf-8">
  <title>AngularJS ui-select</title>

  <!--
      IE8 support, see AngularJS Internet Explorer Compatibility https://docs.angularjs.org/guide/ie
      For Firefox 3.6, you will also need to include jQuery and ECMAScript 5 shim
    -->
  <!--[if lt IE 9]>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/2.2.0/es5-shim.js"></script>
      <script>
        document.createElement('ui-select');
        document.createElement('ui-select-match');
        document.createElement('ui-select-choices');
      </script>
    <![endif]-->

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-sanitize.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-select/0.20.0/select.min.js"></script>
  <!-- ui-select files -->
  <script src="./select.js"></script>
  <link rel="stylesheet" href="./select.css">

  <script src="./demo.js"></script>

  <!-- themes -->
  <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.default.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-select/0.20.0/select.min.css" />
  <style>
    body 
      padding: 15px;
    
    
    .select2>.select2-choice.ui-select-match 
      /* Because of the inclusion of Bootstrap */
      height: 29px;
    
    
    .selectize-control>.selectize-dropdown 
      top: 36px;
    
    /* Some additional styling to demonstrate that append-to-body helps achieve the proper z-index layering. */
    
    .select-box 
      background: #fff;
      position: relative;
      z-index: 1;
    
    
    .alert-info.positioned 
      margin-top: 1em;
      position: relative;
      z-index: 10000;
      /* The select2 dropdown has a z-index of 9999 */
    
  </style>
</head>

<body>
  <div ng-controller="DemoCtrl">


    <h3>Selectize theme</h3>
    <p>Selected: ctrl.asdf</p>
    <ui-select ng-model="ctrl.asdf" theme="selectize" ng-disabled="disabled" style="width: 300px;" title="Choose a country">
      <ui-select-match placeholder="Select or search a country in the list...">$select.selected</ui-select-match>
      <ui-select-choices repeat="country in karthi | filter: $select.search">
        <span ng-bind-html="country | highlight: $select.search"></span>
        <small ng-bind-html="country.code | highlight: $select.search"></small>
      </ui-select-choices>
    </ui-select>
  </div>
</body>

</html>

【讨论】:

@karthicks 如果您的问题得到解决,请关闭问题!

以上是关于ui选择范围模型值中的选择框数组未正确显示的主要内容,如果未能解决你的问题,请参考以下文章

选择框 laravel 未定义的变量

关于 Vue.js+Element-UI 日期控件 日期范围选择

WooCommerce - 提交后检索选择框的正确数据值

带有 Angularjs ng 模型的语义 UI 日期选择器

如何根据淘汰赛js中的单选按钮选择填充文本框

Redux-form Material-UI下拉列表未显示下拉列表,选择