Titanium 钛合金控制器';t曝光器函数
我正在从另一个控制器动态地从一个小部件创建一行。虽然我似乎可以访问视图,但无法访问导出的函数 下面是小部件的控制器代码Titanium 钛合金控制器';t曝光器函数,titanium,appcelerator,appcelerator-titanium,Titanium,Appcelerator,Appcelerator Titanium,我正在从另一个控制器动态地从一个小部件创建一行。虽然我似乎可以访问视图,但无法访问导出的函数 下面是小部件的控制器代码 var moment = require("/lib/moment-with-locales"); var args = $.args; var isSent = true; function configure(data){ $.userImage.image = data.otherUser.attributes["avatar-thumb-url"];
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文件中生成的,则似乎不存在此问题。假设这是您的小部件。XML:
<Alloy>
<View id="widget">
<Label id="userNameLabel"/>
<Label id="userRatingLabel"/>
<Label id="bodyLabel"/>
<Label id="timeLabel"/>
<Label id="statusLabel"/>
</View>
</Alloy>
叫它:
var widget = Alloy.createWidget("chatDetail.chatRow",{}).getView();
widget.sendMessage();
win.add(widget);
var widget = Alloy.createWidget("chatDetail.chatRow",{});
widget.sendMessage();
win.add(widget.getView());
或者,如果尚未调用“getView()”,则返回根目录:
叫它:
var widget = Alloy.createWidget("chatDetail.chatRow",{}).getView();
widget.sendMessage();
win.add(widget);
var widget = Alloy.createWidget("chatDetail.chatRow",{});
widget.sendMessage();
win.add(widget.getView());
假设这是您的widget.xml:
<Alloy>
<View id="widget">
<Label id="userNameLabel"/>
<Label id="userRatingLabel"/>
<Label id="bodyLabel"/>
<Label id="timeLabel"/>
<Label id="statusLabel"/>
</View>
</Alloy>
叫它:
var widget = Alloy.createWidget("chatDetail.chatRow",{}).getView();
widget.sendMessage();
win.add(widget);
var widget = Alloy.createWidget("chatDetail.chatRow",{});
widget.sendMessage();
win.add(widget.getView());
或者,如果尚未调用“getView()”,则返回根目录:
叫它:
var widget = Alloy.createWidget("chatDetail.chatRow",{}).getView();
widget.sendMessage();
win.add(widget);
var widget = Alloy.createWidget("chatDetail.chatRow",{});
widget.sendMessage();
win.add(widget.getView());
当您执行
Ti.API.info(行)时代码>它打印什么?我不认为它是您期望的模块的一个实例。您可以将全局FN放入lib
文件夹中的一个文件中,并将此文件包含在控制器文件中。它打印控制器时包含所有参数,但由于某种原因缺少函数代码>它打印什么?我不认为它是您期望的模块的一个实例。您可以将全局FN放入lib
文件夹中的一个文件中,并将此文件包含在控制器文件中。它打印控制器的所有参数,但由于某种原因缺少函数。