gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:27:43 27 4
gpt4 key购买 nike

我正在为一些简单的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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com