使用Ti.App.Properties.setList()方法时,我遇到了一个奇怪的错误。
在这里你可以看到我有一些价值观。 控制台:
[INFO] : id==2251378
[INFO] : category==[object Object]
[INFO] : localteam.id==18650
[INFO] : visitorteam.id==7636
[INFO] : j==1
[INFO] : i==2
现在我getlist();并保存在变量中,并在第二行创建一个对象并初始化它。并在其中指定一些值。 我的代码是:
var myMatchesFootball = Ti.App.Properties.getList('myMatchesFootball');
myMatchesFootballObject = new Object();
myMatchesFootballObject.matchId = "";
myMatchesFootballObject.data = "";
myMatchesFootballObject.local = "";
myMatchesFootballObject.visitor = "";
myMatchesFootballObject.index_j = "";
myMatchesFootballObject.index_i = "";
myMatchesFootballObject.matchId = json2.scores.category[e.source.star_indexi].matches.match.id;
myMatchesFootballObject.data = json2.scores.category[e.source.star_indexi];
myMatchesFootballObject.local = json2.scores.category[e.source.star_indexi].matches.match.localteam.id;
myMatchesFootballObject.visitor = json2.scores.category[e.source.star_indexi].matches.match.visitorteam.id;
myMatchesFootballObject.index_j = e.source.star_indexj;
myMatchesFootballObject.index_i = e.source.star_indexi;
myMatchesFootballObject.selectedDay = "myMatches";
myMatchesFootball.push(myMatchesFootballObject);
Ti.App.Properties.setList('myMatchesFootball', myMatchesFootball);
但我的应用程序崩溃并在控制台中显示此错误
The Error is:
[ERROR] : Script Error {
[ERROR] : column = 62;
[ERROR] : line = 888;
[ERROR] : message = "Attempt to insert non-property list object (\n {\n data = {\n \"file_group\" = brazil;\n gid = 1139;\n id = 1139;\n matches = {\n date = \"Jan 11\";\n \"formatted_date\" = \"11.01.2017\";\n match = (\n {\n \"commentary_available\" = \"\";\n date = \"Jan 11\";\n events = \"<null>\";\n \"fix_id\" = 2042614;\n \"formatted_date\" = \"11.01.2017\";\n ht = {\n score = \"\";\n };\n id = 2251377;\n localteam = {\n goals = \"?\";\n id = 7139;\n name = \"Cajazeirense de Desportos\";\n };\n \"static_id\" = 2159519;\n status = \"23:30\";\n time = \"23:30\";\n timer = \"\";\n v = 0;\n venue = \"\";\n visitorteam = {\n goals = \"?\";\n id = 17805;\n name = \"Botafogo PB\";\n };\n },\n {\n \"commentary_available\" = \"\";\n date = \"Jan 11\";\n events = \"<null>\";\n \"fix_id\" = 2042611;\n \"formatted_date\" = \"11.01.2017\";\n ht = {\n score = \"\";\n };\n id = 2251378;\n localteam = {\n goals = \"?\";\n id = 18650;\n name = CSP;\n };\n \"static_id\" = 2159516;\n status = \"23:30\";\n time = \"23:30\";\n timer = \"\";\n v = 0;\n venue = \"\";\n visitorteam = {\n goals = \"?\";\n id = 7636;\n name = \"Treze PB\";\n };\n },\n {\n \"commentary_available\" = \"\";\n date = \"Jan 11\";\n events = \"<null>\";\n \"fix_id\" = 2042610;\n \"formatted_date\" = \"11.01.2017\";\n ht = {\n score = \"\";\n };\n id = 2251379;\n localteam = {\n goals = \"?\";\n id = 7366;\n name = \"Internacional PB\";\n };\n \"static_id\" = 2159515;\n status = \"23:30\";\n time = \"23:30\";\n timer = \"\";\n v = 0;\n venue = \"\";\n visitorteam = {\n goals = \"?\";\n id = 20327;\n name = Paraiba;\n };\n },\n {\n \"commentary_available\" = \"\";\n date = \"Jan 11\";\n events = \"<null>\";\n \"fix_id\" = 2042612;\n \"formatted_date\" = \"11.01.2017\";\n ht = {\n score = \"\";\n };\n id = 2251380;\n localteam = {\n goals = \"?\";\n id = 27182;\n name = \"Serrano PB\";\n };\n \"static_id\" = 2159517;\n status = \"23:30\";\n time = \"23:30\";\n timer = \"\";\n v = 0;\n venue = \"\";\n visitorteam = {\n goals = \"?\";\n id = 7150;\n name = \"Auto Esporte\";\n };\n },\n {\n \"commentary_available\" = \"\";\n date = \"Jan 11\";\n events = \"<null>\";\n \"fix_id\" = 2042613;\n \"formatted_date\" = \"11.01.2017\";\n ht = {\n score = \"\";\n };\n id = 2251381;\n localteam = {\n goals = \"?\";\n id = 7619;\n name = \"Sousa EC\";\n };\n \"static_id\" = 2159518;\n status = \"23:30\";\n time = \"23:30\";\n timer = \"\";\n v = 0;\n venue = \"\";\n visitorteam = {\n goals = \"?\";\n id = 7195;\n name = Campinense;\n };\n }\n );\n };\n name = \"Brazil: Campeonato Paraibano\";\n };\n date = \"11.01.2017\";\n \"index_i\" = 2;\n \"index_j\" = 1;\n local = 18650;\n matchId = 2251378;\n name = \"Brazil: Campeonato Paraibano\";\n selectedDay = myMatches;\n time = \"23:30\";\n visitor = 7636;\n }\n) for key myMatchesFootball";
[ERROR] : sourceURL = "file:///Users/Apple/Library/Developer/CoreSimulator/Devices/1C82A7E8-F480-4FE1-A0F2-C6F713774B0D/data/Containers/Bundle/Application/500CCBD6-B81D-4D6A-AB8E-0C8E24E379D8/Tipping%20Hub.app/alloy/controllers/football_window_detail.js";
[ERROR] : stack = "[native code]\nfile:///Users/Apple/Library/Developer/CoreSimulator/Devices/1C82A7E8-F480-4FE1-A0F2-C6F713774B0D/data/Containers/Bundle/Application/500CCBD6-B81D-4D6A-AB8E-0C8E24E379D8/Tipping%20Hub.app/alloy/controllers/football_window_detail.js:888:62";
[ERROR] : }
但是当我评论这一行时,它运作良好,
myMatchesFootballObject.data = json2.scores.category[e.source.star_indexi];
我也尝试这个但不行,
myMatchesFootballObject.data = new Object;
答案 0 :(得分:0)
您遇到此错误的原因是您尝试保存嵌套对象并且setList / getList API不支持它,因此您收到错误Attempt to insert non-property list object
解决方案是将该对象串化并存储它,但是,我不建议将其作为最佳实践。您应该使用Alloy模型使用数据库,而不是将其保存在Ti.App.Properties
您可以在代码中更改一些内容以改进它:
将变量默认为空数组。
var myMatchesFootball = Ti.App.Properties.getList('myMatchesFootball', []);
不是调用new Object
,而是声明对象并为其赋值。 (不要忘记开头的var)
var myMatchesFootballObject = {
matchId: json2.scores.category[e.source.star_indexi].matches.match.id,
data: JSON.stringify(json2.scores.category[e.source.star_indexi]),
// Add other values
};
其余的都没问题:
myMatchesFootball.push(myMatchesFootballObject);
Ti.App.Properties.setList('myMatchesFootball', myMatchesFootball);