2
我有一個提供MySQL日期的Rails服務器。我的課程是基於AngularDart教程設置的。它似乎沒有正確加載。將JSON日期加載到Dart日期時間
我的artist_service。鏢法:
Future<List<Record>> getArtistsRecords(int id) async {
String url = 'http://catbox.loc/artists/${id.toString()}/records'; // Rails: artists/:id/records
try {
HttpRequest response = await HttpRequest.request(
url, requestHeaders: headers);
List data = JSON.decode(response.responseText);
final records = data
.map((value) => new Record.fromJson(value))
.toList();
return records;
}
catch (e) {
throw _handleError(e);
}
}
我artist.dart工廠方法:
factory Record.fromJson(Map<String, dynamic> record) =>
new Record(_toInt(record['id']),
record['title'],
record['catalog'],
record['artist_id'],
record['label_id'],
record['style_id'],
record['alternate_catalog'],
record['recording_date'],
record['notes'],
record['penguin'],
record['category']
);
有問題的元件是recording_date
,它被聲明爲DateTime
。當我在html中包含{{recording_date}}
時,例如,我得到1958-03-09
。如果我嘗試{{ recording_date | date}}
,它會將錯誤視爲無效格式。我懷疑我沒有正確設置DateTime
對象。工廠方法可以這樣做嗎?