我試圖實現簡單的JSON操作:SenchaTouch的簡單JSON示例
我想在我的頁面上寫入來自JSON格式文件的文本。
的文件是這樣的:(data.json)
{
"id": "0",
"name":"myname"
}
該腳本獲取JSON:(main.js)
Ext.setup({
onReady: function() {
Ext.regModel('Person', {
fields: [
{name: 'id', type: 'string'},
{name: 'name', type: 'string'}
]
});
//I want the name to be written on the page
var itemTemplate = new Ext.XTemplate(
'<tpl for=".">',
'{name}',
'</tpl>');
// I get and decode the Json from data.json
var jsonStore = new Ext.data.Store({
model: "Person",
proxy: {
type: 'ajax',
url: 'data.json',
reader: {
type: 'json'
}
},
autoLoad: true
});
// The panel should get the stored Result and display it
var jsonPanel = new Ext.Panel ({
title: "json",
fullscreen: true,
items: [
{
xtype: 'list',
store: jsonStore,
itemTpl:itemTemplate,
}
]
});
}
});
的index.html
文件調用的所有文件及以上sencha-touch.js
和.css
。 我只是不能看到任何寫在頁面上的東西。
如果有人能給我一個關於我在做什麼錯誤的線索,這將有很大幫助。
確定語法不正確,但它不足以讓它工作 – COcdm
我在這裏試過並且該示例有效。你把這些文件放到Apache的文件夾(或其他網絡服務器)中,還是試圖直接從瀏覽器運行? – eduardosouza