2

すべてのフィールドが sencha touch の json ファイルから取得される動的フォームを作成するにはどうすればよいですか?

(「回答」から転送された追加の詳細)

私のjsonは次のようになります{

  success: true,
 data: [
     {xtype: "textfield", title: "label1", name: "textfield1"},
     {xtype: "emailfield", title: "label2", name: "textfield2"},
     {xtype: "passwordfield", title: "label3", name: "textfield3"},
     {xtype: "button", title: "button", name: "button"}




  ]
}

別のコントローラーとビューが必要です。私はこのような単一のコントローラーファイルでそれをしました

       form = Ext.create('MyApp.view.MyDataView');
var test=this;



                var ajax = Ext.Ajax.request({
            url: 'contacts.json',
            method: 'get',
            success: function(response)
             {

            console.log(response);               
            response = Ext.JSON.decode(response.responseText);
                           this.hello=response;
            console.log(response.data.length);  
                for (var i = 0; i < response.data.length; i++) 
                {
                    form.add({
                        xtype: response.data[i].xtype,
                        id:response.data[i].title,
                                        action:response.data[i].title,
                        label: response.data[i].title,
                        name: response.data[i].name

                             });


                                                }


                    console.log(form.getValues());

                                form.setLayout();


                                form.show(document.body);
                Ext.Viewport.animateActiveItem(form,{type: 'flip', direction: 'right'});

 } 

utton タップイベントに関して私が直面している問題があり、複数のボタンがある場合、それらにイベントを与えることはまだできません....これに関して誰か助けてもらえますか..

4

1 に答える 1

0

もう何か試しましたか?

次のようなファイルにフォームを作成するだけです。

{
    xtype: 'form',
    items: [ //...
    ]
}

次に、ファイルをロードして、変数にデコードできます。

Ext.Ajax.request({
    url: 'yourform.json',
    success: function(response){
        var formInJson = response.responseText;
        var form = Ext.JSON.decode(formInJson);
        //... do something with your form
    }
});
于 2013-02-14T12:09:38.923 に答える