Sencha Touch selectfield 项目选择问题

发布于 2024-12-14 13:49:20 字数 1554 浏览 4 评论 0原文

这是我的模型和商店,

    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...',
  }); 

所示这是服务器返回的 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>

我可以看到商店正在从网络服务器获取值,并且我可以看到带有代理名称和用户 ID 值的数据对象。我们使用 Sencha touch 1.1.0。我现在可以看到选择字段中从 Web 服务填充的值。当我选择一个项目时,所选项目不会更改为我选择的项目。我看到商店中的第一个元素已被选中。我们该如何解决这个问题?请建议。

Here is my Model and Store,

    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); 

I'm setting this store to my selectitem like this

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...',
  }); 

Here is my XML file the server returns

<?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>

I can see store is getting values from the webserver and I can see the data object with agentname and userid values. We are using Sencha touch 1.1.0. I can now see the values in the selectfield that are populated from the webservice. When I select an item the selected item is not changing to the item I selected. I see the first element in my store as selected. How do we fix this? Please suggest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当爱已成负担 2024-12-21 13:49:20

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...',
                                }]

The Sencha touch documentation is so vague. Could have been better with some examples at every property and method to show how to use it. Here is how I fixed my problem. I have to do it with typical Jquery Ajax request.

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
       });

and in MainForm.js the select control goes like this

items: [  {
                                     xtype: 'selectfield',
                                     id: 'selectfield',
                                     name: 'agent',
                                     label: 'Agent',
                                     options: App.Agents,
                                     placeHolder: 'Click to select options...',
                                }]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文