【发布时间】:2014-05-31 05:03:13
【问题描述】:
我正在尝试将本地 sqlite dB(我已经测试过并且值在那里)中的值加载到我可以在我的视图中使用的全局模型中。当我在使用Ti.API.info(library.at(i));in index.js 创建模型后尝试打印模型的值时,它大部分时间返回未定义,有时还会返回像function lastIndexOf() { [native code] } 这样的函数调用。发生了什么事,我该如何解决?这是我的模型(UpcomingRaces.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');
【问题讨论】:
标签: javascript sqlite model titanium appcelerator