2011-11-09 10 views
0

は私のモデルとストア、煎茶タッチselectfield項目選択問題

Ext.regModel('Agent', { fields: [{ name: 'userid', type: 'int' }, { name: 'agentname', type: 'string'}] }); 

App.stores.agentStore = new Ext.data.Store({ 
    model: 'Agent', 
    storeId: 'AgentsStoreid', 
    proxy: { 
     type: 'ajax', 
     url: 'https://abc123.com/wsbrightdoor.asmx/GetAgents?username=abc&password=123', 
     reader: { type: 'xml', root: 'root', record: 'salesagent' } 
    }, 
    autoLoad: true 
}); 

    //App.stores.agentStore.load(); 
    console.log(App.stores.agentStore); 

である私は、ここでは、この

var sel = new Ext.form.Select(
    { 
    id: 'Myselectfield', 
          name: 'myagent', 
          label: 'Agent', 
          store: App.stores.agentStore, 
          displayField: 'agentname', 
          valueFiels: 'userid', 
          placeHolder: 'Click/touch to select options...', 
    }); 

ように私のSelectItemにこのストアを設定しています私のXMLファイルであるサーバが

を返します。
<?xml version="1.0" encoding="utf-8"?> 

<root> 

    <salesagent> 

    <userid>1</userid> 

    <agentname>Name1</agentname> 

    </salesagent> 

    <salesagent> 

    <userid>13</userid> 

    <agentname>Name2</agentname> 

    </salesagent> 

</root> 

ストアがWebサーバーから値を取得しているのがわかります。エージェント名とユーザーIDを持つデータオブジェクトが表示されます値。 Sencha touch 1.1.0を使用しています。私は今、Webサービスから移入されselectfield内の値を見ることができます。私は項目を選択すると、選択した項目は、私が選択した項目に変更されていません。選択したように私は私の店の最初の要素を参照してください。これをどのように修正するのですか?提案してください。

答えて

1

Sencha touchのドキュメントは非常に曖昧です。それを使う方法を示すために、すべてのプロパティとメソッドでいくつかの例を使った方が良いでしょう。ここで私の問題を解決した方法です。私は典型的なjQueryのAjaxリクエストでそれをしなければなりません。

AgentsArray = new Array(); //Create an Array that saves the Agents AgentsArray.push({ text: '', value: '0' }); 


pushAgents = function (data, textStatus, xml_http_req) 
{ 
    //console.log(data); 
    /*read the agents and IDs from XML and build Array*/ 
    $(data).find('salesagent').each(
            function() 
            { 
             var agentName = $(this).find('agentname').text(); 
             var agentId = $(this).find('userid').text(); 
             AgentsArray.push({ text: agentName, value: agentId }); // push the items into Array 
             //alert(agentName); 
            } 
            ); 


            return AgentsArray; 
} 


function somethingWrong() { 
    AgentsArray.push('SomethingWentWrong', '0'); 
} 
App.Agents = AgentsArray; //Save it in the array and this is specified in the Mainform.js(View). 


$.ajax({ 
      url: 'https://abc.com/def.asmx/GetAgents', 
      type: 'GET', 
      dataType: 'xml', 
      data: 'abc=1&def=1&username=123', 
      success: pushAgents, 
      errors: somethingWrong 
     }); 

とMainForm.jsに選択制御は、この

items: [ { 
            xtype: 'selectfield', 
            id: 'selectfield', 
            name: 'agent', 
            label: 'Agent', 
            options: App.Agents, 
            placeHolder: 'Click to select options...', 
           }] 
のようになります
関連する問題