私はいくつかの製品/ブランドを持っているショップをフィルタリングし、その結果をリストコンポーネントに表示するウェブサイト用のアプリケーションを構築しています。私は、データをロードするまでのすべての方法を持って、ブランド/国/都市をコンボボックスに入れて、ユーザーがどの国と都市を見たいのか、どんなブランドを選ぶことができるようにします。今まで問題はない。私の問題は、dataproviderは、各エントリのアイテムレンダラーに使用するラベルにいくつかの値をハードコードするときに必要な作業ですが、データプロバイダから実際のデータを取得することはできません。 VGroupコンポーネント(リストの各ショップで使用しています)に4つのラベルがあり、3つのラベルがハードコードされています。ラベルの1つは、実際のデータをxmlファイルから取得しようとしています。私が見たすべてのチュートリアル(そしてドキュメントも)では、誰もが単に "data.XYZ"とヒットします。ここで、XYZは取得する属性またはノードの名前です。私の場合でも同じことをすると、 "1120:未定義のプロパティデータへのアクセス"というエラーが返されます。何が間違っているのですか?数時間のうちにフレックスのサンプルを数百回繰り返しています。新しいバージョンと古いバージョンの両方があり、何をすべきかを知ることはできません。残りのすべてが入っているとき、この最後の小さなものに固執するのは本当に神経を壊す!コードを見て、間違ったやり方をしたのか、何かを逃したのかどうか教えてください!以下のコードを投稿してください。 xmlファイルもありますが、正しく読み込まれており、別のxmlListsには正しいノードが格納されています。そうでないと思わない限り、投稿する必要はありません。各ショップのxmlノードは、 "title"、 "tel"、 "mail"、 "city"です。タイトルを取得しようとしています。最も重要な機能は、filterShopsと、もちろんlist全体とitemrendererブロックです。フレックスアプリケーションのデータプロバイダからデータを取得できない
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="815" height="578" minWidth="955" minHeight="600"
creationComplete="sendData()">
<fx:Style source="styles.css"/>
<fx:Declarations>
<s:HTTPService id="shopsService" url="data/places.xml" result="shopsService_return(event)" resultFormat="e4x"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
import spark.events.IndexChangeEvent;
private var placesXML:XMLList;
[Bindable] private var countriesList:XMLListCollection;
[Bindable] private var brandsList:XMLListCollection;
[Bindable] private var citiesList:XMLListCollection;
[Bindable] private var shopsList:XMLListCollection;
[Bindable] public var gridList:XMLListCollection;
private var selectedCountry:int = 0;
private var selectedCountryId:int = 0;
private var selectedBrand:int = 0;
private var selectedCity:int = 0;
private var selectedBrandId:int = 0;
private var selectedCityId:int = 0;
private function sendData():void {
shopsService.send();
}
private function shopsService_return(event:ResultEvent):void {
placesXML = XMLList(event.result);
brandsList = new XMLListCollection(placesXML.brands.brand);
citiesList = new XMLListCollection(placesXML.countries.country[0].cities.city);
shopsList = new XMLListCollection(placesXML.shops.shop);
gridList = new XMLListCollection();
}
private function onBrandboxChange(event:IndexChangeEvent):void {
selectedBrand = event.target.selectedIndex;
selectedBrandId = placesXML.brands.brand[selectedBrand].attribute("id");
filterShops(selectedCountryId.toString(),selectedBrandId.toString(),selectedCityId.toString());
}
private function onCityboxChange(event:IndexChangeEvent):void {
selectedCity = event.target.selectedIndex;
selectedCityId = placesXML.countries.country[selectedCountry].cities.city[selectedCity].attribute("id");
filterShops(selectedCountryId.toString(),selectedBrandId.toString(),selectedCityId.toString());
}
private function englandClick(event:MouseEvent):void
{
citiesList = new XMLListCollection(placesXML.countries.country[0].cities.city);
selectedCountry = 0;
selectedCountryId = 1;
}
private function scotlandClick(event:MouseEvent):void
{
citiesList = new XMLListCollection(placesXML.countries.country[1].cities.city);
selectedCountry = 1;
selectedCountryId = 2;
}
private function filterShops(countryId:String,brandId:String,cityId:String):void {
var xmlCountryId:String;
var indexOfBrandId:int;
var xmlCityId:String;
//outputLabel.text = countryId+"-"+brandId+"-"+cityId;
for (var i:int = 0; i < shopsList.length; i++) {
xmlCountryId = shopsList[i].attribute("country");
xmlCityId = shopsList[i].attribute("city");
if (xmlCountryId == countryId && xmlCityId == cityId) {
indexOfBrandId = shopsList[i].attribute("brands").toString().split(",").indexOf(brandId);
if (indexOfBrandId > -1) gridList.addItem(shopsList[i]);
}
outputLabel.text = shopsList[0].title;
}
}
]]>
</fx:Script>
<s:List id="outputWindow" x="10" y="230" width="795" height="338" borderVisible="false"
dataProvider="{gridList}">
<s:layout>
<s:TileLayout
requestedColumnCount="4"
requestedRowCount="2"
horizontalGap="2"
verticalGap="2"/>
</s:layout>
<s:itemRenderer>
<fx:Component>
<s:VGroup width="180" height="90">
<s:Label styleName="item-title" text="{data.title}" />
<s:Label color="#868686" fontFamily="pfHighwayRegular" fontSize="12" paddingBottom="-2"
paddingTop="-2" styleName="item-text" text="Tel: 0120 230 3777"/>
<s:Label styleName="item-text" text="Mail: [email protected]"/>
<s:Label styleName="item-link" text="Web: www.2012ltd.co.uk"/>
</s:VGroup>
</fx:Component>
</s:itemRenderer>
</s:List>
<s:Button x="6" y="8" label="England" click="englandClick(event)"/>
<s:Button x="125" y="8" label="Scotland" click="scotlandClick(event)" />
<s:Button x="261" y="10" label="Wales"/>
<s:Button x="400" y="10" label="Ireland"/>
<s:ComboBox x="505" y="56" id="brandBox" dataProvider="{brandsList}" change="onBrandboxChange(event)" />
<s:ComboBox x="659" y="56" id="cityBox" dataProvider="{citiesList}" change="onCityboxChange(event)" />
<s:Label id="outputLabel" x="10" y="119" text="Label"/>
</s:Application>
Hiyaユーザー、これは話すプログラムです:)。コンポーネントをインライン定義から抜き出し、別のファイルで定義すれば、これにより、VGroupに実装を追加してIDropInListItemRendererとIDataRendererを実装する際に、やや混乱を招くことはありません。これは、データプロパティとレンダラー内のlistDataプロパティを持つことを意味します。データには、各レンダラーで使用されるリストの1つの要素が割り当てられます(または使用されます)。listDataはメインリストとdataProviderなどのデータのインデックス – shaunhusain
他にも、gridListに何が入っているのか分かりません。また、ノードの代わりにXML内の属性を使用している場合は、属性名の前に@記号を使用する必要があります。 – shaunhusain
私はあまりにもその方法を試みます。 gridListはaddItemを使用してfilterShops関数に取り込まれます。それは、リストの要素を埋める何も表示されませんリストの原因を補完します:)属性はIDだけであり、実際のデータはノード内にあるので、必要はありません。私はこのようにやってみると戻ってきます。 – geodeath