1

わかりましたので、私はTitaniumを初めて使用し、Javascriptの初心者です

私はこれをやってみました:

app.view.newMatrix = function() {
return {
    matrix = Titanium.UI.createWindow({  
        title:'Add a New Matrix',
        backgroundColor:'stripped',
        navBarHidden: false
    }),     
    // navbar buttons
    cancel = Titanium.UI.createButton({
        title:'Cancel'
    }),
    save = Titanium.UI.createButton({
        title:'Save',
        style:Titanium.UI.iPhone.SystemButton.SAVE
    }),
    name_label = Titanium.UI.createLabel({
        text: "Matrix Name:",
        font: { fontsize: 12, fontstyle: 'italic', color: '#336699' },
        height: 35,
        top: 35,
        left: 30,
        width: 150,
        color: "black"
    }),
    name = Titanium.UI.createTextArea({
        color: '#336699',
        height: this.name_label.height,
        top: this.name_label.top + 35,
        left: this.name_label.left - 10,
        width: 275,
        borderRadius:15
    }),
    setItems = function() {
        this.win.add(this.name);
        this.win.add(this.name_label);
        this.win.add(this.desc);
        this.win.add(this.desc_label);
        Ti.API.info("label:"+ this.name_label.height);
        return this.win.open({modal: true, animation: true});  
    }
}

}

次に、次のように呼び出しました。

app.controller.home = function() {
        var home = app.view.home();
        home.setItems();

        home.butn.addEventListener("click", function(e){
            app.controller.newMatrix();
        });

        home.butn2.addEventListener("click", function (e) {
            matrix_table(tab);
        });

        home.butn3.addEventListener("click", function(e){
            newItem();
        });

        home.butn5.addEventListener("click", function (e) {
            item_table(); 
        });

}

ここでTitanium MVCの提案を見たのでこれを行いましたが、匿名オブジェクトを返す理由がわかりません。オブジェクトname_label内からのようにプロパティにアクセスできません。name代わりにこれを行う必要があることがわかりました:

app.view.newMatrix = function() {
    this.matrix = Titanium.UI.createWindow({  
        title:'Add a New Matrix',
        backgroundColor:'stripped',
        navBarHidden: false
    }), 
    // navbar buttons
    this.cancel = Titanium.UI.createButton({
        title:'Cancel'
    }),

    this.save = Titanium.UI.createButton({
        title:'Save',
        style:Titanium.UI.iPhone.SystemButton.SAVE
    }),

    this.name_label = Titanium.UI.createLabel({
        text: "Matrix Name:",
        font: { fontsize: 12, fontstyle: 'italic', color: '#336699' },
        height: 35,
        top: 35,
        left: 30,
        width: 150,
        color: "black"
    }),

    this.name = Titanium.UI.createTextArea({
        color: '#336699',
        height: this.name_label.height,
        top: this.name_label.top + 35,
        left: this.name_label.left - 10,
        width: 275,
        borderRadius:15
    }),

    this.setItems = function() {
        this.win.add(this.name);
        this.win.add(this.name_label);
        this.win.add(this.desc);
        this.win.add(this.desc_label);
        Ti.API.info("label:"+ this.name_label.height);
        return this.win.open({modal: true, animation: true});  
    }

}

次のように呼び出します。

app.controller.home = function() {
return {
    getView: function() {

        var home = app.view.home();
        home.setItems();

        home.butn.addEventListener("click", function(e){
            app.controller.newMatrix();
        });

        home.butn2.addEventListener("click", function (e) {
            matrix_table(tab);
        });

        home.butn3.addEventListener("click", function(e){
            newItem();
        });

        home.butn5.addEventListener("click", function (e) {
            item_table(); 
        });
    }
}

}

しかし、最初の例がうまくいかない理由がわかりません。つまり、プロパティは変数と同じではありませんか? また、2 番目の例もオブジェクトであることを知っています。また、2 番目の例では、newキーワードはオプションですか? 使うべきですか?いつ使うべきかわからないので、ちょっと避けたかったのです。

ありがとうございます。私はそれを機能させていますが、2番目の例が正しい方法であるかどうかはわかりません....

4

0 に答える 0