ExtJs加载数据
我正在尝试从 imdb 加载数据,但表(GridPanel)中没有结果。 这是我的源代码:
...
<body>
<script type="text/javascript">
Ext.onReady(function(){
var store1 = new Ext.data.JsonStore({
root: 'root',
idProperty: 'ID',
remoteSort: true,
fields: [
'Title'
],
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
proxy: new Ext.data.ScriptTagProxy({
url: 'http://www.imdbapi.com/?t=True%20Grit'
})
});
// building grid panel
});
</script>
<div id="topic-grid"></div>
...
也许我应该更改 JsonStore 中的“root”参数?
更新
我尝试使用 HttpProxy,但仍然没有结果。我把我所有的身体内容也许会更有帮助。
<script type="text/javascript">
Ext.onReady(function(){
var store1 = new Ext.data.JsonStore({
reader: new Ext.data.JsonReader({
fields: ['Title'],
root: 'rows'
}),
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
proxy: new Ext.data.HttpProxy({
url: 'http://www.imdbapi.com/?t=True%20Grit'
}),
autoLoad: true
});
var grid1 = new Ext.grid.GridPanel({
width:700,
height:500,
title:'ExtJS.com - Browse Forums',
store: store1,
trackMouseOver:false,
disableSelection:true,
loadMask: true,
// grid columns
columns:[{
id: 'Title',
header: "Topic",
dataIndex: 'Title',
width: 420,
sortable: true
}]
});
// render it
grid1.render('topic-grid');
// trigger the data store load
store1.load({params:{start:0, limit:25}});
});
</script>
<div id="topic-grid"></div>
I'm trying to load data from imdb, but i have no results in table (GridPanel).
It's my source code:
...
<body>
<script type="text/javascript">
Ext.onReady(function(){
var store1 = new Ext.data.JsonStore({
root: 'root',
idProperty: 'ID',
remoteSort: true,
fields: [
'Title'
],
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
proxy: new Ext.data.ScriptTagProxy({
url: 'http://www.imdbapi.com/?t=True%20Grit'
})
});
// building grid panel
});
</script>
<div id="topic-grid"></div>
...
Maybe should I change 'root' parameter in JsonStore?
UPDATE
I tried to use HttpProxy, but still no results. I put my all body contents maybe it will be more helpful.
<script type="text/javascript">
Ext.onReady(function(){
var store1 = new Ext.data.JsonStore({
reader: new Ext.data.JsonReader({
fields: ['Title'],
root: 'rows'
}),
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
proxy: new Ext.data.HttpProxy({
url: 'http://www.imdbapi.com/?t=True%20Grit'
}),
autoLoad: true
});
var grid1 = new Ext.grid.GridPanel({
width:700,
height:500,
title:'ExtJS.com - Browse Forums',
store: store1,
trackMouseOver:false,
disableSelection:true,
loadMask: true,
// grid columns
columns:[{
id: 'Title',
header: "Topic",
dataIndex: 'Title',
width: 420,
sortable: true
}]
});
// render it
grid1.render('topic-grid');
// trigger the data store load
store1.load({params:{start:0, limit:25}});
});
</script>
<div id="topic-grid"></div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 ScriptTagProxy 时,您无法直接从响应中获取 JSON。您只能获取可执行的 javascript,不幸的是,imdbapi 站点不返回可执行的 javascript。此外,您不能使用 HttpProxy 执行跨站点脚本 (XSS)。您只能连接到您自己的本地域上的资源(例如文件)。
您的一种可能性是:
使用与服务器端文件联系的 HttpProxy,而不是 ScriptTagProxy。
让服务器端文件代表客户端进行 imdb api 调用,并将 imdb api 的结果以 JSON 形式输出回客户端。
有关更多详细信息,请参阅此在各种服务器端技术中执行上述建议的示例。
You can't get a JSON directly from the response when using a ScriptTagProxy. You can only get executable javascript, and unfortunately, the imdbapi site doesn't return executable javascript. Also, you can't use HttpProxy to do cross-site scripting (XSS). You can only make connections to resources (e.g., files) on your own local domain.
One possibility for you:
Instead of a ScriptTagProxy, use an HttpProxy that contacts your server-side file.
Have your server-side file make the imdb api call on behalf of the client and output the results of the imdb api as a JSON back to the client.
See this for more details and examples of doing the above suggestion in various server-side technologies.