钛合金Appcelerator -模型到本地sqlite数据库未定义的值
Titanium Appcelerator - Model to local sqlite dB undefined values
我正试图从本地sqlite dB(我已经测试和值在那里)加载值到一个全局模型,我可以在我的视图中使用。当我尝试在index.js中使用Ti.API.info(library.at(i));
创建模型后打印模型的值时,它在大多数时间返回未定义,有时像function lastIndexOf() { [native code] }
这样的函数调用。发生了什么,我该如何解决?这是我的模型(upcominggrace .js):
exports.definition = {
config: {
columns: {
"Name": "string",
"Location": "string",
"Date": "string",
"Url": "string"//,
//"Id" : "INTEGER PRIMARY KEY AUTOINCREMENT"
},
defaults: {
"Name": "string",
"Location": "string",
"Date": "string",
"Url": "string"
},
adapter: {
type: "sql",
collection_name: "UpcomingRaces",
//idAttribute: "Id"
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// extended functions and properties go here
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// extended functions and properties go here
comparator: function(UpcomingRaces) {
return UpcomingRaces.get('Name');
}
});
return Collection;
}
};
这是我是如何读取它到一个模型(index.js):
var library = Alloy.Collections.UpcomingRaces;
library.fetch();
function prepareView()
{
// Automatically Update local DB from remote DB
updateRaces.open('GET', 'http://fakeurl.com/api/UpcomingRaces');
updateRaces.send();
library && library.fetch();
// Read DB to create current upcomingRaces model
// Insert the JSON data to the table view
for ( var i in library ) {
Ti.API.info(library.at(i));
data.push(Alloy.createController('row', {
Name : library[i]['Name'],
Date : library[i]['Date']
}).getView());
}
$.table.setData(data);
}
我在alloy.js文件中也有这个
Alloy.Collections.UpcomingRaces = Alloy.createCollection('UpcomingRaces');
问题是你的for循环:
// Insert the JSON data to the table view
for ( var i in library ) { // i here is an instance of the Model, not an index
Ti.API.info(library.at(i)); // <-- error here
data.push(Alloy.createController('row', {
Name : library[i]['Name'],
Date : library[i]['Date']
}).getView());
}
不需要调用library.at(i),只使用i元素。所以正确的代码应该是:
// Insert the JSON data to the table view
for ( var element in library ) {
Ti.API.info(JSON.stringify(element));
data.push(Alloy.createController('row', {
Name : element.get('Name'),
Date : element.get('Date')
}).getView());
}
相关文章:
- PHP:显示sqlite数据库中的html格式数据,使用tinymce保存
- 是否可以使用NativeScript使用Sqlite数据库
- 使用Javascript将多条记录插入SQLite数据库时出错
- 连接SQlite数据库
- 以html形式显示sqlite数据库中的数据(phonegap)
- 如何访问Chrome创建的SQLITE数据库
- 如何从 sqlite 获取所有数据库名称和表名
- 使用 SQL .js在 JavaScript 中加载 SQLite 数据库
- Phonegap应用程序SQLite数据库初始设置
- 将捕获的图像存储到SQlite数据库中?(科尔多瓦)
- 将捕获的图像插入数据库问题(Cordova/SQlite/JavaScript)
- 将SQLite数据库存储在IndexedDB中
- 有没有一种简单的方法可以通过javascript将MySQL文件导入SQLite数据库
- 我想将长文本文档解析为SQLite数据库.如何转义所有不支持的字符
- Windows 8应用程序Javascript和SQlite(数据库已锁定)
- 从sqlite数据库查询数据结果文件名
- 如何将具有phonegap数据库SQLite查询的内部函数的值返回到外部函数
- 本地存储vs数据库(SQLite)的cordova应用程序
- Ionic Framework (AngularJS)和数据库SQLite
- Phonegap拍摄照片并将图像(BLOB)插入数据库SQLite