我刚刚开始使用Sencha Touch 2.0。我在阅读XML数据时遇到问题。我从下载的基本“入门”应用程序开始,它工作正常,这意味着我已经正确完成了设置。现在我已经对一些简单的XML进行了一些修改,但是我无法在屏幕上看到任何数据。以下是我的代码。请帮我解决一下这个。 - 这里有app.js文件的内容 -Sencha Touch读取XML数据
Ext.Loader.setPath({
'Ext': 'lib/touch/src'
});
Ext.define('User', {
extend: 'Ext.data.Model',
config: {
fields: ['id', 'name', 'email']
}
});
var mystore = Ext.create('Ext.data.Store', {
model: 'User',
autoLoad: true,
proxy: {
type: 'ajax',
url : 'userData.xml',
reader: {
type: 'xml',
rootProperty: 'users',
record: 'user'
}
}
});
Ext.application({
name: 'Sencha',
launch: function() {
//The whole app UI lives in this tab panel
Ext.Viewport.add({
xtype: 'tabpanel',
fullscreen: true,
tabBarPosition: 'bottom',
items: [
// This is the home page, just some simple html
{
title: 'Home',
iconCls: 'home',
cls: 'home',
scrollable: true,
html: [
'<img height=260 src="http://staging.sencha.com/img/sencha.png" />',
'<h1>Welcome to Sencha Touch</h1>',
"<p>Building the Getting Started app</p>",
'<h2>Sencha Touch (2.0.0)</h2>'
].join("")
},
{
xtype: 'list',
title: 'Events',
iconCls: 'star',
itemTpl: '{id}',
store: mystore
}
]
});
}
});
的XML是在相同的位置,因为这app.js文件。请注意,我没有安装任何服务器。我只是对app.js进行更改,然后在Chrome浏览器中打开“index.html”。
这是XML。它是一样的煎茶Docs.-给出的
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
<id>112</id>
<name>Ed Spencer</name>
<email>[email protected]</email>
</user>
<user>
<id>248</id>
<name>Abe Elias</name>
<email>[email protected]</email>
</user>
</users>
这里是更改后,我的代码 -
Ext.Loader.setPath({
'Ext': 'lib/touch/src'
});
Ext.regModel('Personal', {
fields : [
'id',
{name: 'name', type: 'string'},
{name: 'email', type: 'string'}
]
});
Ext.application({
name: 'Sencha',
launch: function() {
//The whole app UI lives in this tab panel
Ext.Viewport.add({
xtype: 'tabpanel',
fullscreen: true,
tabBarPosition: 'bottom',
items: [
// This is the home page, just some simple html
{
xtype : 'selectfield',
name : 'user',
label : 'Users',
store : new Ext.data.Store({
model : 'Personal',
autoLoad : true,
proxy : {
type : 'ajax',
url : 'userData.xml',
reader : {
type : 'xml',
root : 'users'
}
}
}),
valueField : 'name',
displayField : 'name'
}
]
});
}
});
现在感到沮丧!。从早上开始尝试,但没有运气......文档和指南也非常简短,没有太多帮助.... Adobe Flex文档更好,并且非常容易理解....: - ((( – GordanWebb
*** Very重要 - 在sencha论坛上,有个人问我控制台说什么 - 这是它说的 - XMLHttpRequest无法加载file:/// E:/sencha%20trials/userData.xml?_dc = 1340003241745&page = 1&start = 0&limit = 25。 Origin-null是Access-Control-Allow-Origin不允许的......我想这就是问题所在。现在检查如何解决这个问题...如果你知道解决方案,请在这里发帖n ..感谢:) – GordanWebb
你好,我的问题解决了...... Chrome不允许通过Ajax进行本地文件访问......我安装了Web服务器XAMPP..and并执行了代码......并且它工作......我很高兴。 ..保持联系... :) – GordanWebb