简体   繁体   English

ExtJS:从组合中的选定商店中获取信息

[英]ExtJS: Fetching information from selected store in combo

I have the following ExtJS Textfield that lives in a form. 我有以下ExtJS Textfield,它以一种形式存在。 I have a store called store_Product that fetches data via ajax proxy and suggest them to the PCODE field. 我有一个名为store_Product的商店,该商店通过ajax代理获取数据并将其建议给PCODE字段。

In reality this store has many other fields such as price , color , size and so on.. I am trying to set an onchange listener on this field such that when the user select the PCODE, it delivers other information (of the Product selected) to other fields in the page. 实际上,这家商店还有许多其他字段,例如pricecolorsize等。.我试图在此字段上设置onchange侦听器,以便当用户选择PCODE时,它会提供(所选产品的)其他信息。到页面中的其他字段。

The code bellows work. 该代码波纹管工作。 The console.log(store_Product.data) correctly fetches the data from the model. console.log(store_Product.data)正确地从模型中获取数据。 However , the data fetched is of the whole store. 但是 ,获取的数据是整个存储的。 I just want the one selected. 我只想选择一个。 How would I change this code to do that. 我将如何更改此代码来做到这一点。

            {
                fieldLabel: 'PCODE  ',
                name: 'pcode',
                typeAhead: true,
                xtype: 'combo',
                store: store_Product,
                displayField: 'pcode',
                valueField: 'pcode',
                allowBlank:false,
                minChars:1,
                forceSelection:true,
                hideTrigger:true,
                queryDelay: 0,
                listeners:{
                   change: function(combo,value){
                       console.log(store_Product.data)
                   }
                }
            }

Thanks. 谢谢。

Of course it's gonna log everything. 当然,它将记录所有内容。 Have you tried looking at the value you're receiving in the handler? 您是否尝试过查看处理程序中收到的value

change: function(combo, value) {
   console.log(value);
   var idx= store_Product.find('pcode', value),
       record = store_Product.getAt(idx);

   console.log(record);
}

如果pcode是记录的ID ,则可以使用Store.getById

store_Product.getById(value)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM