加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular ui-grid:具有多个选择的下拉列表

发布时间:2020-12-17 16:56:10 所属栏目:安全 来源:网络整理
导读:我试图在anguler-ui-grid中使用多个select但是得到错误: TypeError: value.forEach is not a function at writeNgOptionsMultiple [as writeValue] (angular.js:26579) at ngModelCtrl.$render (angular.js:28680) at Object.ngModelWatch (angular.js:2549
我试图在anguler-ui-grid中使用多个select但是得到错误:

TypeError: value.forEach is not a function
at writeNgOptionsMultiple [as writeValue] (angular.js:26579)
at ngModelCtrl.$render (angular.js:28680)
at Object.ngModelWatch (angular.js:25493)
at Scope.$digest (angular.js:15888)
at angular.js:16091
at completeOutstandingRequest (angular.js:5552)
at angular.js:5829(anonymous function) @ angular.js:12520(anonymous function) @ angular.js:9292Scope.$digest @
angular.js:15914(anonymous function) @
angular.js:16091completeOutstandingRequest @ angular.js:5552(anonymous
function) @ angular.js:5829

以下是代码:官方模板中唯一的变化是下拉模板tpl中的“multiple”属性

var app = angular.module('app',['ngTouch','ui.grid','ui.grid.edit']);

app.controller('MainCtrl',['$scope',function ($scope) {

  var myData = [
    {
        "firstName": "Cox","lastName": "Carney","employed": true
    },{
        "firstName": "Lorraine","lastName": "Wise","employed": false
    },{
        "firstName": "Nancy","lastName": "Waters","employed": false
    }
];

var dropDownArray = [
      { id: 'Gabi',firstName: 'Gabi' },{ id: 'Gabriel',firstName: 'Gabriel' }];


$scope.msg = "hello shit";

var tpl = '<div>
  <form
    name="inputForm">
    <select multiple
      ng-class="'colt' + col.uid"
      ui-grid-edit-dropdown
      ng-model="MODEL_COL_FIELD"
      ng-options="field[editDropdownIdLabel] as field[editDropdownValueLabel] CUSTOM_FILTERS for field in editDropdownOptionsArray">
    </select>
  </form>
</div>';

$scope.gridOptions = { data: myData,columnDefs: [{ field: 'firstName',displayName: 'First Name',width: 190,editableCellTemplate: tpl,editDropdownValueLabel: 'firstName',editDropdownOptionsArray: dropDownArray },{ field: 'lastName',displayName: 'Last Name',width: 180 },{ field: 'employed',displayName: 'employed?',width: 180 }]}
}]);

解决方法

我遇到了同样的问题 – 一个很难的问题,因为它适用于角度1.2但不适用于1.4.
我的解决方案是初始字段值必须是数组,而不是字符串.
所以你的数据必须如下所示:

var myData = [
    {
        "firstName": ["Cox"],{
        "firstName": ["Lorraine"],{
        "firstName": ["Nancy"],"employed": false
    }
];

错误应该消失.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读