在 Flex 中使用 HTTPService 加载 XML 文件
所以我一直在尝试将数据从 XML 文件加载到数据网格中。该项目采用 Cairngorm 框架。 XML 文件位于 Web 内容文件夹中。我在 Services 文件夹中有一个 HTTPService 调用。
<mx:HTTPService
id = "getCategory"
url = "assets/CategoryDept21Class1.xml"
resultFormat = "e4x"
/>
当我在一个 dataGrid 中进行选择时,它应该使用 XML 文件中的数据填充另一个 dataGrid。下面是类数据网格。当我单击一个类时,它应该填充下一个数据网格。
<mx:DataGrid rowCount="10" enabled="true"
dataProvider="{classList}"
verticalScrollPolicy="on"
click = "onClass()"
id="classes" width="192" top="73" left="253" height="225">
<mx:columns>
<mx:DataGridColumn headerText="#" dataField="merchandiseClassNumber" width="50"/>
<mx:DataGridColumn headerText="Class Name" dataField="merchandiseClassDescription" width="150"/>
</mx:columns>
</mx:DataGrid>
这些是将被触发的方法。
private function selectClass(evt:ResultEvent):void{
//this.categoryList = new XMLListCollection(evt.result.resultSet);
this.categoryList= evt.result.resultSet.MerchandiseAssortmentCategory;
var request:AMTCategoryEvent;
CairngormEventDispatcher.getInstance().dispatchEvent(request);
}
private function onClass():void{
//Alert.show("you just clicked on a class ");
var event:AMTCategoryEvent = new AMTCategoryEvent();
CairngormEventDispatcher.getInstance().dispatchEvent(event);
}
这就是我在委托中定义 getCategory() 的方式
public function getCategory() : void
{
service = ServiceLocator.getInstance().getHTTPService("getCategory") as HTTPService;
//Alert.show(service.url);
var token : AsyncToken = service.send();
token.addResponder(responder);
}
,这就是我在 getCategoryCommand 中的定义。
public function execute(event: CairngormEvent) : void{
var categoryEvent: AMTCategoryEvent = event as AMTCategoryEvent;
var deleg:Delegate = new Delegate(this);
deleg.getCategory();
//deleg.getCategory(categoryEvent.deptNumber, categoryEvent.classNum);
}
public function result(info:Object) :void{
trace("Get Category: Success");
// __model.categoryList = new XMLList(info.result.resultSet.MerchandiseAssortmentCategory);
var xmlbleh:XMLList=info.result.resultSet.MerchandiseAssortmentCategory.lastResult;
mx.controls.Alert.show(xmlbleh.toXMLString());
__model.categoryList = new XMLListCollection(XMLList(info.result.resultSet.MerchandiseAssortmentCategory.lastResult));
}
由于某种原因,它没有将 xml 文件中的数据读取到数据网格中。这是我在这个网站上的第一个问题,我不知道我的问题是否清楚。但我该怎么做呢?谢谢 :)
So I have been trying to load data from an XML file into a datagrid. The project is in Cairngorm framework. The XML file is in the web content folder. I have a HTTPService call in the Services folder.
<mx:HTTPService
id = "getCategory"
url = "assets/CategoryDept21Class1.xml"
resultFormat = "e4x"
/>
When I make a selection in one dataGrid it is supposed to populate another dataGrid with the data in the XML file. Below is the Classes datagrid. When i click on a class it is supposed to populate the next data grid.
<mx:DataGrid rowCount="10" enabled="true"
dataProvider="{classList}"
verticalScrollPolicy="on"
click = "onClass()"
id="classes" width="192" top="73" left="253" height="225">
<mx:columns>
<mx:DataGridColumn headerText="#" dataField="merchandiseClassNumber" width="50"/>
<mx:DataGridColumn headerText="Class Name" dataField="merchandiseClassDescription" width="150"/>
</mx:columns>
</mx:DataGrid>
These are the methods that will be triggered.
private function selectClass(evt:ResultEvent):void{
//this.categoryList = new XMLListCollection(evt.result.resultSet);
this.categoryList= evt.result.resultSet.MerchandiseAssortmentCategory;
var request:AMTCategoryEvent;
CairngormEventDispatcher.getInstance().dispatchEvent(request);
}
private function onClass():void{
//Alert.show("you just clicked on a class ");
var event:AMTCategoryEvent = new AMTCategoryEvent();
CairngormEventDispatcher.getInstance().dispatchEvent(event);
}
this is how i defined getCategory() in my delegate
public function getCategory() : void
{
service = ServiceLocator.getInstance().getHTTPService("getCategory") as HTTPService;
//Alert.show(service.url);
var token : AsyncToken = service.send();
token.addResponder(responder);
}
and this is what i have in my getCategoryCommand.
public function execute(event: CairngormEvent) : void{
var categoryEvent: AMTCategoryEvent = event as AMTCategoryEvent;
var deleg:Delegate = new Delegate(this);
deleg.getCategory();
//deleg.getCategory(categoryEvent.deptNumber, categoryEvent.classNum);
}
public function result(info:Object) :void{
trace("Get Category: Success");
// __model.categoryList = new XMLList(info.result.resultSet.MerchandiseAssortmentCategory);
var xmlbleh:XMLList=info.result.resultSet.MerchandiseAssortmentCategory.lastResult;
mx.controls.Alert.show(xmlbleh.toXMLString());
__model.categoryList = new XMLListCollection(XMLList(info.result.resultSet.MerchandiseAssortmentCategory.lastResult));
}
It is not reading the data in the xml file into the datagrid for some reason. This is my first question on this website I don't kno if my question is clear. But how would i do that? Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题很清楚,但您可能有可能有用的额外信息。我将尝试通过一系列问题来阐明这些问题。 (这可能属于注释,但那里有大小限制,并且可能会变得很麻烦)
1-我希望您能够在委托中获取 HttpService 的引用。
2-我希望您能够调试直到进行异步服务调用。
3-我假设结果回调函数从未被调用。 (或就此而言的错误)。
4- 我假设应用程序部署在 Web 服务器中。
如果我所有的假设都是正确的,那么问题可能出在 url 的形成上。我假设您试图提供相对路径,但我会尝试提供绝对网址。如果问题出在 url 上,那么服务调用应该已记录在您的后台中,并且您应该会看到类似 404 的错误消息。
如果没有明显的错误消息,则这可能是安全错误。您是否提供了跨域策略文件。
如果我的假设有错误,请填写必要的信息。另请提供Flex SDK版本。
注意:如果您将其作为独立应用程序运行,则存在安全限制,不允许您从文件系统读取数据,除非您在 Flash Builder 中提供其他属性。
The question is clear enough, but you might have extra information that might be useful. I will try to elucidate those through a series of questions. (This probably belongs to comments, but there is size limits there and it might become cumbersome)
1- I hope that you managed to get the reference of the HttpService in your delegate.
2- I hope that you managed to debug till the point that the async service call is made.
3- I assume that the result call back function is never called. ( or fault for that matter).
4- I assume that the application is deployed in a web server.
If all my assumptions are right, then the problem could be with the formation of url. I assume you are trying to provide a relative path, but I will try to provide absolute url. If the problem is with the url, then the service call should have been logged in your back ground and you should be seeing a error message like 404).
If there are no apparent error messages, then this could be a security error. Did you provide crossdomain policy file.
If any of my assumptions are wrong, please fill in with necessary information. Also please provide the Flex SDK version.
Note: In case if you are running this as a standalone application, then there is a security constraint that will not allow you to read from file system, unless you provide additional attributes in your Flash Builder.