如何给一个包含json格式数据的js变量赋值?
有一个这样的js变量varoptions={chart:{},series:[]};现在想使series:[{name:'Tokyo',data:[7.0,6.9,9.5...
有一个这样的js变量
var options = {
chart:{
},series:[
]
};
现在想使series:[{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
name: 'New York',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
}, {
name: 'Berlin',
data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]
假如有一个变量data = "";data里面是字符串,包含series需要的数据,
请问应该怎么给option.series赋值? 展开
var options = {
chart:{
},series:[
]
};
现在想使series:[{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
name: 'New York',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
}, {
name: 'Berlin',
data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]
假如有一个变量data = "";data里面是字符串,包含series需要的数据,
请问应该怎么给option.series赋值? 展开
2个回答
展开全部
1 var ds = new Ext.data.Store({
2 proxy: new Ext.data.ScriptTagProxy({
3 url: 'yoururl.json'
4 }),
5 reader: new Ext.data.JsonReader({
6 root: 'Fields',
7 totalProperty: 'totalCount',
8 id: 'id'
9 }, [
10 ,
11
12 ])
13 });
14 var combobox = new Ext.form.ComboBox({
15 id:'combobox',
16 x:0,
17 y:20,
18 store: da,
19 displayField:'field',
20 typeAhead: false,
21 loadingText: '正在加载字段...',
22 forceSelection: false,
23 triggerAction: 'all',
24 hideTrigger:false,
25 minChars:1,
26 anchor: '100%',
27 pageSize:10
28 });
json输出
注意stcCallback1007要用程序输出请求过来的参数callback的值
stcCallback1007(,,,,,,,,]});stcCallback1007(,,,,,,,,]});stcCallback1007(,,,,,,,,]});
不好意思,看错了,以下是grid的
// create the Data Store
var singleTablestore = new Ext.data.JsonStore({
root: 'topics',
totalProperty: 'totalCount',
idProperty: 'tableid',
remoteSort: true,
fields: [
,'name','description','importdate'
],
// load using script tags for cross domain, if the data in on the same domain as
proxy: new Ext.data.ScriptTagProxy({
url: 'abc.json'
})
});
singleTablestore.setDefaultSort('date', 'desc');
var singleTable = new Ext.grid.EditorGridPanel({
id:'singleTable-panel',
layout:'anchor',
anchor:['100%','100%'],
title:'单表数据处理',
store: singleTablestore,
//trackMouseOver:false,
//disableSelection:true,
loadMask: true,
autoScroll:true,
// grid columns
columns:[{
id: 'name',
header: "数据表名称",
dataIndex: 'name',
width: 200,
sortable: true,
renderer:renderTips
},{
id: 'description', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b )
header: "数据表描述",
dataIndex: 'description',
renderer:renderTips2,
editor:new Ext.form.TextField(),
width: 270,
// renderer: renderTopic,
sortable: true
},{
header: "导入日期",
dataIndex: 'importdate',
width: 150,
sortable: true
},{
id: 'tableid',
header: "操作",
dataIndex: 'tableid',
width: 450,
resizable: false,
//editor:new Ext.Button()
renderer: renderLast
//items:[new Ext.Button()]
}],
// customize view config
viewConfig: {
//forceFit:true,
enableRowBody:true,
//showPreview:true
},
// paging bar on the bottom
bbar: new Ext.PagingToolbar({
pageSize: 20,
store: singleTablestore,
displayInfo: true,
displayMsg: '当前显示 - 条,共 条',
beforePageText:'第',
afterPageText:'页,共页',
emptyMsg: "没有相应内容",
items:[
'-', {
pressed: true,
enableToggle:true,
text: 'Show Preview',
cls: 'x-btn-text-icon details',
toggleHandler: function(btn, pressed){
...
}
}]
})
});
singleTable.on('afteredit', afterEdit, this );
singleTable.on('show', function()});}, this );
function afterEdit(e) {
...
}
abc.json
stcCallback1009(,]});
2 proxy: new Ext.data.ScriptTagProxy({
3 url: 'yoururl.json'
4 }),
5 reader: new Ext.data.JsonReader({
6 root: 'Fields',
7 totalProperty: 'totalCount',
8 id: 'id'
9 }, [
10 ,
11
12 ])
13 });
14 var combobox = new Ext.form.ComboBox({
15 id:'combobox',
16 x:0,
17 y:20,
18 store: da,
19 displayField:'field',
20 typeAhead: false,
21 loadingText: '正在加载字段...',
22 forceSelection: false,
23 triggerAction: 'all',
24 hideTrigger:false,
25 minChars:1,
26 anchor: '100%',
27 pageSize:10
28 });
json输出
注意stcCallback1007要用程序输出请求过来的参数callback的值
stcCallback1007(,,,,,,,,]});stcCallback1007(,,,,,,,,]});stcCallback1007(,,,,,,,,]});
不好意思,看错了,以下是grid的
// create the Data Store
var singleTablestore = new Ext.data.JsonStore({
root: 'topics',
totalProperty: 'totalCount',
idProperty: 'tableid',
remoteSort: true,
fields: [
,'name','description','importdate'
],
// load using script tags for cross domain, if the data in on the same domain as
proxy: new Ext.data.ScriptTagProxy({
url: 'abc.json'
})
});
singleTablestore.setDefaultSort('date', 'desc');
var singleTable = new Ext.grid.EditorGridPanel({
id:'singleTable-panel',
layout:'anchor',
anchor:['100%','100%'],
title:'单表数据处理',
store: singleTablestore,
//trackMouseOver:false,
//disableSelection:true,
loadMask: true,
autoScroll:true,
// grid columns
columns:[{
id: 'name',
header: "数据表名称",
dataIndex: 'name',
width: 200,
sortable: true,
renderer:renderTips
},{
id: 'description', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b )
header: "数据表描述",
dataIndex: 'description',
renderer:renderTips2,
editor:new Ext.form.TextField(),
width: 270,
// renderer: renderTopic,
sortable: true
},{
header: "导入日期",
dataIndex: 'importdate',
width: 150,
sortable: true
},{
id: 'tableid',
header: "操作",
dataIndex: 'tableid',
width: 450,
resizable: false,
//editor:new Ext.Button()
renderer: renderLast
//items:[new Ext.Button()]
}],
// customize view config
viewConfig: {
//forceFit:true,
enableRowBody:true,
//showPreview:true
},
// paging bar on the bottom
bbar: new Ext.PagingToolbar({
pageSize: 20,
store: singleTablestore,
displayInfo: true,
displayMsg: '当前显示 - 条,共 条',
beforePageText:'第',
afterPageText:'页,共页',
emptyMsg: "没有相应内容",
items:[
'-', {
pressed: true,
enableToggle:true,
text: 'Show Preview',
cls: 'x-btn-text-icon details',
toggleHandler: function(btn, pressed){
...
}
}]
})
});
singleTable.on('afteredit', afterEdit, this );
singleTable.on('show', function()});}, this );
function afterEdit(e) {
...
}
abc.json
stcCallback1009(,]});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询