更改字符串会使整个脚本无法在 Titanium 中运行
所以我有一个脚本可以创建一个简单的表视图,但是更改一个简单的字符串似乎会产生严重的后果。
这是有效的(我已将其剥离到相关部分):
data = [];
db = Ti.Database.install('../data.sqlite', 'person');
rows = db.execute('SELECT * FROM person');
while (rows.isValidRow()) {
data.push({
title: rows.fieldByName('first_name'),
hasChild: true,
c_id: rows.fieldByName('C_ID')
});
rows.next();
}
tableview = Titanium.UI.createTableView({
data: data
});
...
win.add(tableview);
...
但是将 title: rows.fieldByName('first_name'),
更改为 title: rows.fieldByName('first_name') + rows。 fieldByName('last_name'),
抛出错误 表达式 'win.add' [] 的结果不是函数。在persons.js(第32行)
(第32行是win.add(tableview)
。
唯一的区别是该行,但它使整个脚本失败。
提前致谢
弗雷德
So I have a script which creates a simple table view, but changing a simple string seems to have drastic consequences.
This works (I have stripped it to the relevant parts):
data = [];
db = Ti.Database.install('../data.sqlite', 'person');
rows = db.execute('SELECT * FROM person');
while (rows.isValidRow()) {
data.push({
title: rows.fieldByName('first_name'),
hasChild: true,
c_id: rows.fieldByName('C_ID')
});
rows.next();
}
tableview = Titanium.UI.createTableView({
data: data
});
...
win.add(tableview);
...
But changing title: rows.fieldByName('first_name'),
to title: rows.fieldByName('first_name') + rows.fieldByName('last_name'),
throws an error ofResult of expression 'win.add' [] is not a function. at persons.js (line 32)
(line 32 is win.add(tableview)
.
The only difference is that line but it makes the whole script fail.
Thanks in advance
Fred
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过在它们之间添加空格?
title: rows.fieldByName('first_name') + ' ' + rows.fieldByName('first_name')
如果您从表中取出另一个表?像last_name之类的,它也会崩溃吗?
Have you tried to put a blank space between them?
title: rows.fieldByName('first_name') + ' ' + rows.fieldByName('first_name')
and if you take another table from the table? like last_name or so, does it crash then too?
我发现了问题,这是因为我使用的 CoffeeScript 将代码包装在函数包装器中,这会导致问题(以某种方式)。删除函数包装器修复了它,但现在我不能再使用咖啡脚本了。
I found the problem, it was because I'm using coffeescript which wraps the code in a function wrapper, which causes problems (somehow). Removing the function wrapper fixed it but now I can't use coffeescript any more.