[英]Sencha Touch — Put JSON variable into Data Store?
I have a variable with JSON in it (it's a variable because I got it using JQuery from a local file...offline, so this was necessary). 我有一个带有JSON的变量(这是一个变量,因为我是使用JQuery从本地文件中获取的...离线,所以这是必需的)。 Anyway, how do I get it so this is seen as a JSON inside of a store? 无论如何,如何获取它,以便将其视为商店内部的JSON?
I tried the following, but it doesn't load. 我尝试了以下操作,但未加载。
// jData is the variable with the JSON
var jData = loadJSON("sampledata.json");
Ext.regModel('myStore', {
fields: [
{name:"Name",type:"string"},
{name:"id",type:"int"}
]
});
var myStore = new Ext.data.Store({
model: 'myStore',
autoLoad: true,
proxy: {
data: jData,
reader: {
type: 'json'
}
}});
JSON looks like: [{"Name": "High", "id": 1},{"Name": "Medium", "id": 2},{"Name": "Low", "id": 3}] JSON看起来像:[{“ Name”:“ High”,“ id”:1},{“ Name”:“ Medium”,“ id”:2},{“ Name”:“ Low”,“ id”: 3}]
I am building an Android app and upon using: 我正在构建一个Android应用,并且使用了:
alert(jData);
I receive the JSON perfectly, but can't figure out how to get it into the Store to be used in a selectfield 我完美地收到了JSON,但无法弄清楚如何将其放入应用商店以在选择字段中使用
There are multiple ways to do this. 有多种方法可以做到这一点。 The simplest way is: 最简单的方法是:
// jData is the variable with the JSON
var jData = loadJSON("sampledata.json");
Ext.regModel('myStore', {
fields: [
{name:"Name",type:"string"},
{name:"id",type:"int"}
]
});
var myStore = new Ext.data.Store({
model: 'myStore',
data: jData
});
If this does not work try this: 如果这不起作用,请尝试以下操作:
// jData is the variable with the JSON
var jData = loadJSON("sampledata.json");
Ext.regModel('myStore', {
fields: [
{name:"Name",type:"string"},
{name:"id",type:"int"}
]
});
var myStore = new Ext.data.Store({
model: 'myStore',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'sampledata.json',
reader: {
type: 'json'
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.