Extjs code:
Ext.Loader.setConfig({
enabled:true
});
Ext.application({
name: 'Importtool',
launch: function () {
Ext.define('Task', {
extend: Ext.data.Model,
fields: [
{ name: 'task', type: 'string' },
{name:'id' ,type:'string'},
{ name: 'uniqueid', type: 'string' },
{ name: 'parentid', type: 'string' },
{ name: 'startdate', type: 'string' },
{name:'enddate',type:'string'}
]
});
var store = Ext.create('Ext.data.TreeStore', {
model: 'Task',
proxy: {
type: 'ajax',
url: 'mpp.aspx/GetData'
},
});
Ext.create('Ext.tree.Panel', {
title: 'Tree Grid',
width: 1300,
height: 450,
store: store,
rootVisible: false,
useArrows: true,
lines: false,
scope: this,
renderTo: 'tree-view',
columns: [{
xtype: 'treecolumn',
text: 'Task',
flex: 1,
sortable: true,
dataIndex: 'task'
}, {
text: 'Id',
sortable: true,
width: 150,
dataIndex: 'id'
}, {
text: 'Unique Id',
width: 150,
sortable: true,
dataIndex: 'uniqueid'
},
{
text: 'Parent ID',
width: 150,
sortable: true,
dataIndex: 'parentid'
},
{
text: 'Start Date',
width: 150,
sortable: true,
dataIndex: 'startdate'
},
{
text: 'End Date',
width: 150,
sortable: true,
dataIndex: 'enddate'
}],
});
}
});
Asp.net code:
public void GetTasks()
{
System.Collections.Generic.List<Tasks> lstTasks = new System.Collections.Generic.List<Tasks>();
foreach (Task task in ToEnumerable(projectObj.getAllTasks())) //Gets all tasks from mpp file
{
lstTasks.Add(new Tasks
{
TaskName = task.getName(),
TaskId = Convert.ToString(task.getID()),
TaskUniqueId = Convert.ToString(task.getUniqueID()),
//Level = Convert.ToString(task.getOutlineLevel()).Trim(),
//OutLine = Convert.ToString(task.getOutlineNumber())
TaskParentId = Convert.ToString(task.getOutlineLevel()),
StartDate = Convert.ToString(task.getStart()),
EndDate=Convert.ToString(task.getFinish()),
TaskCompletePercent=Convert.ToString(task.getPercentageComplete())
});
// rpt_tasks.DataSource = lstTasks;
// rpt_tasks.DataBind();
}
string json = JsonConvert.SerializeObject(lstTasks);
Response.Write(json);
}
问题是当我运行此代码时出现无法解析 JSON 警告。所以我不明白真正的问题是什么。我是 Ext Js 的新手。我想在 extjs 树网格中显示 mpp 文件数据。最近几天我一直在网上搜索参考资料,但没有一个例子,所以我非常渴望解决这个问题。请指导我解决这个问题。