我有一个对象列表:class DisplayTransactions extends StatefulWidget {
final TransactionType tmptransType;
final FinanceTransBlock transacBloc;
final Function onSelectionChanged;
int SelectedItemsCount;
/// -1 expense 1 income
DisplayTransactions(
{Key key,
@required this.tmptransType,
@required this.transacBloc,
this.SelectedItemsCount,
this.onSelectionChanged})
: super(key: key);
@override
_DisplayTransactionsState createState() => _DisplayTransactionsState();
}
class _DisplayTransactionsState extends State<DisplayTransactions> {
var isSelected = false;
var mycolor = Colors.white;
// int iselectionCount = 0;
@override
Widget build(BuildContext context) {
widget.transacBloc.transacType = widget.tmptransType;
debugPrint("----------------------------- ${widget.tmptransType}");
if (widget.SelectedItemsCount == 0) {// if no rows selected, then reload database based on trans type, eg expense, or income.. etc
widget.transacBloc.refresh();
}
return StreamBuilder<List<FinanceTransaction>>(
stream: widget.transacBloc.transacations,
builder: (context, snapshot) {
if (snapshot.hasData) {
List<FinanceTransaction> list = snapshot.data;
// return buildTaskListWal(snapshot.data);
return Padding(
我尝试通过网络套接字发送此列表,但我缺少的是一个{ "name":"John", "birth":"1986-12-14", "city":"New York"}
属性,它看起来像是:
"msg_code"
如何将msg_code附加到对象列表?
{ "msg_code": "ListUsers", "name":"John", "birth":"1986-12-14", "city":"New York"}
尝试将msg_code属性赋予用户列表:
var users = LoadUsers(); // List of Users ({ "name":"John", "birth":"1986-12-14", "city":"New York"}) etc..
string output = new JavaScriptSerializer().Serialize(users);
session.Send(output);
答案 0 :(得分:2)
要插入新对象,只需将对象的键和值传递给它。示例:
let myObj = { "name":"John", "birth":"1986-12-14", "city":"New York"}
console.log(myObj)
myObj['msg_code'] = 'listUsers'
console.log(myObj)