2016-05-30 9 views
0

私はウィジェットから作られた行を別のコントローラから動的に作成しています。ビューにアクセスしているようですが、エクスポートされた関数にアクセスすることはできません。チタン合金コントローラのコンストラクタが関数を公開しない

ここにウィジェットのコントローラコードがあります。

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ファイルで生成された場合、この問題は存在しないようです。あなたのウィジェットに機能を追加するなど、それを直接設定することができ、あなたの.jsコントローラで

<Alloy> 
    <View id="widget"> 
     <Label id="userNameLabel"/> 
     <Label id="userRatingLabel"/> 
     <Label id="bodyLabel"/> 
     <Label id="timeLabel"/> 
     <Label id="statusLabel"/> 
    </View> 
</Alloy> 

$.widget.sendMessage = sendMessage; 

コール

+0

あなたは 'Ti.API.info(行)を行うと、'それが何を印刷していますか?私はそれがあなたが期待しているモジュールのインスタンスではないということです。 – developer82

+0

グローバルなfnを 'lib'フォルダのファイルにすることができます。コントローラファイルにこのファイルを含めてください。 –

+0

コントローラはすべてのパラメータを表示しますが、何らかの理由で機能が失われました。 –

答えて

2

が、これはあなたのウィジェットの.xmlであると言うことができますそれは:

var widget = Alloy.createWidget("chatDetail.chatRow",{}).getView(); 
widget.sendMessage(); 
win.add(widget); 

またはルートに

、あなたはまだ 'getViewメソッドを()' を呼び出していなかった場合:

$.sendMessage = sendMessage; 

はそれを呼び出します。

var widget = Alloy.createWidget("chatDetail.chatRow",{}); 
widget.sendMessage(); 
win.add(widget.getView()); 
関連する問題