我的flartter dart脚本中有一个问题,这是我的脚本:
List<ReplyTile> replytile = new List<ReplyTile>();
replytile.add(
new ReplyTile(
member_photo: "photo",
member_id: "001",
date: "01-01-2018",
member_name: "Denis",
id: "001",
text: "hallo.."
)
);
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何删除上的项目List<ReplyTile>有id = 001..?
提前致谢
Gün*_*uer 27
removeWhere 允许这样做:
replytile.removeWhere((item) => item.id == '001')
Run Code Online (Sandbox Code Playgroud)
另请参见List Dartdoc
Cod*_*ker 23
//For removing specific item from a list with the attribute value
replytile.removeWhere((item) => item.id == '001')
//Remove item by specifying the position of the item in the list
replytile.removeAt(2)
//Remove last item from the list
replytile.removeLast()
//Remove a range of items from the list
replytile.removeRange(2,5)
Run Code Online (Sandbox Code Playgroud)
Suz*_*tha 14
在您的情况下,这有效:
replytile.removeWhere((item) => item.id == '001');
Run Code Online (Sandbox Code Playgroud)
对于具有特定数据类型(例如 int)的列表,删除也有效。例如:
List id = [1,2,3];
id.remove(1);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12079 次 |
| 最近记录: |