【发布时间】:2016-05-30 21:46:04
【问题描述】:
我正在从另一个控制器动态创建由小部件组成的行。虽然我似乎可以访问视图,但我无法访问导出的函数。
这是小部件的控制器代码。
var moment = require("/lib/moment-with-locales");
var args = $.args;
var isSent = true;
function configure(data){
$.userImage.image = data.otherUser.attributes["avatar-thumb-url"];
$.userNameLabel.text = Alloy.Globals.getFormattedName(data.otherUser.attributes["first-name"], data.otherUser.attributes["last-name"]);
//$.userRatingLabel.text = data.userRating;
$.bodyLabel.text = data.messages[0].attributes.body;
$.timeLabel.text = new moment(data.messages[0].attributes.timestamp).fromNow();
}
function setSentStatus(sent){
isSent = sent;
$.statusLabel.height = 15;
if(sent == false){
$.statusLabel.color = Alloy.CFG.colors.red;
} else {
$.statusLabel.color = Alloy.CFG.colors.grey0;
}
};
function sendMessage(){
Alloy.Globals.fluidAPI.postMessage(JSON.stringify({
"data": {
"type": "message",
"attributes": {
"body": data.messages[0].attributes.body,
"recipient_id": data.otherUser.id
}
}
}), function(postMessageResponse){
if(postMessageResponse){
Ti.API.info(postMessageResponse);
}
});
}
exports.configure = configure;
exports.setSentStatus = setSentStatus;
exports.sendMessage = sendMessage;
configure(args.data);
当我从另一个控制器调用“sendMessage()”函数时。它找不到它。
var row = Alloy.createWidget("chatDetail.chatRow", {message: {attributes:{body: $.toolbarTextArea.getValue(), timestamp: new moment().toISOString()}}, user: Alloy.Globals.currentUserData});
Ti.API.info(row);
controllers.push(row);
$.tableView.appendRow(row.getView());
$.tableView.scrollToIndex($.tableView.data[0].rows.length-1);
row.sendMessage();
有人知道我需要做什么才能访问这些功能吗?如果小部件是在视图 XML 文件中生成的,则似乎不存在此问题。
【问题讨论】:
-
当您执行
Ti.API.info(row);时,它会打印什么?我不认为它是您期望的模块的一个实例。 -
您可以将全局 fns 放入
lib文件夹中的文件中,并将此文件包含在您的控制器文件中 -
它打印控制器的所有参数,但由于某种原因缺少功能。
标签: titanium appcelerator appcelerator-titanium