我试图创建一个程序使用飞镖保存html文件中的联系人。本地存储不工作 - 飞镖
这是我的代码中镖:
import 'dart:html';
void saveContact() {
Storage localStorage = window.localStorage;
var txtFirst = query("#firstname");
String first = txtFirst.text;
var txtLast = query("#lastname");
String last = txtLast.text;
var txtEmail = query("#email");
String email = txtEmail.text;
var txtMobile = query("#mobile");
String mobile = txtMobile.text;
var txtHome = query("#home");
String home = txtHome.text;
var txtOffice = query("#office");
String office = txtOffice.text;
var contact = {
"firstname" : first,
"lastname" : last,
"email" : email,
"mobile" : mobile,
"home" : home,
"office" : office
};
localStorage.setItem(first + " " + last, JSON.stringify(contact));
var test2 = JSON.parse(localStorage.getItem(first + " " + last));
var result = query("#divContents");
result.text = test2.tostring();
}
void main() {
querySelector('#savecontacts').onClick.listen(saveContact);
}
我想输出的div的一个接触只是为了看看镖代码工作。但没有任何反应......请帮助。
我没有用自己的localStorage尚,HTTPS://pub.dartlang。 org/packages/lawndart可能会提供一些想法如何使用它或此问题http://stackoverflow.com/questions/12062593/how-do-i-save-a-value-from-a-text-input-box-并加载它后来在飞镖/ 12062594#12062594 –