dart - Dart -模型不稳定-组件

标签 dart angular-dart

我正在为一些简单的CRUD操作扩展angular.dart教程。我正在尝试做一个漂亮的智能组合框(下拉框),该组合框采用KeyValuePairs列表并返回Selected KeyValyePair。
不幸的是,我收到此错误。

Model did not stabilize in 10 digests. Last 3 iterations:
itemsMap: collection: Instance of 'KeyValuePair'[null -> 0], Instance of 'KeyValuePair'[null -> 1]...

有代码。

dropdown_box.dart
    library dropdown_box;

import 'package:angular/angular.dart';
import 'dart:core';
import 'package:tutorial/service/KeyValuePair.dart';
import 'dart:async';


@Component(selector: 'dropdownbox', templateUrl: 'dropdown_box.html', publishAs: 'dropCtrl')
class DropDownComponent {
  // @NgOneWay('items-map')
  // Map<String, String> itemsMap;

  @NgOneWay('items-map')
 List<KeyValuePair> itemsMap;


  @NgTwoWay('selected-keyvalue')
  KeyValuePair selectedKeyValue;

//   void printit(item) {
//    new Future(() {
//      print("${item.value + ' '+ item.key}");
//       SelectedKeyValue = new KeyValuePair(item.key, item.value);
//     });

  String selectedKey;
  void setKeyAsSelected() {

    new Future(() {
      Iterable keyvaluepairs = itemsMap.where((i) => i.key == selectedKey);
      if (keyvaluepairs.length > 0) {
        selectedKeyValue = keyvaluepairs.elementAt(0);
      }
    });

  }

}

dropdown_box.html
<div class=dropdownbox">
  <select ng-model="selectedKey" ng-change="setKeyAsSelected()">
    <option ng-value=""></option>
    <option ng-repeat="item in itemsMap" ng-value="item.key">
     {{item.value}}
      </option>
  </select>
</div>

在recipe_book.html中使用
<dropdownbox items-map="categorieKvList" selected-keyvalue="selectedKV"></dropdownbox>

recipe_book.dart(仅重要部分)
  KeyValuePair selectedKV;

  List<KeyValuePair> _categorieKvList = new List<KeyValuePair>();
  List<KeyValuePair> get categorieKvList {
    _categorieKvList.clear();
   categories.forEach((f)=>
       _AddToList(f, f));
   return _categorieKvList;
  }

  _AddToList(key, value)
  {
    KeyValuePair kvpair = new KeyValuePair.fromValues(key, value); //new KeyValuePair().AddValues(key, value);
    _categorieKvList.add(kvpair);
  }

键值对
library KeyValuePair;

import 'package:angular/angular.dart';

@Injectable()
class KeyValuePair {
  dynamic key;
  dynamic value;

//  AddValues(key, value) {
//    this.key = key;
//    this.value = value;
//  }

  KeyValuePair();
  KeyValuePair.fromValues(dynamic this.key, dynamic this.value);
}

最佳答案

categorieKvList的getter每次调用时都会返回带有新的KeyValu对的已更改的_categorieKvList。这被 Angular 解释为变化。

更改逻辑,以便_categorieKvList仅在其数据源(类别)更改时才被修改。

关于dart - Dart -模型不稳定-组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27672541/

相关文章:

flutter - 如何在导航上放置父级小部件的同级

Dart-在每次测试之后或之前如何运行功能?

Flutter:将数据发送回特​​定列表项

dart - 从函数返回类

dart - 如何知道何时加载组件?

dart - AngularDart中的基准测试变化检测

routing - Dart 多服务器中的端口转发请求//隔离处理程序

json - 将 JSON 日期加载到 Dart DateTime

dart - Angulardart Markdown指令不起作用

dart - DARTFMT搞砸了@Component装饰器格式