Permalink
Browse files

添加获取学生新后台处理,添加后台处理取出model类名

  • Loading branch information...
1 parent b247069 commit ac792ce0d2721086bd8d12ada0ffc4c622dae309 @mouse-lin committed Mar 22, 2012
@@ -1,2 +1,12 @@
class StudentsController < ApplicationController
+ #获取学生信息
+ def get_all_students
+ students = []
+ Student.all.each do |s|
+ students.push(s.attributes.merge!({
+ :class_name => s.classes.try(:name)
+ }))
+ end
+ render_json students
+ end
end
View
@@ -2,4 +2,5 @@
require File.expand_path('../application', __FILE__)
# Initialize the rails application
+ActiveRecord::Base.include_root_in_json = false
Pf::Application.initialize!
View
@@ -13,6 +13,12 @@
get "index"
end
end
+ resources :students do
+ collection do
+ get "get_all_students"
+ end
+ end
+
@@ -1,6 +1,7 @@
Pf.settings.homeIndex = {
panel: function(){
var grid = new Pf.classes.student();
+ grid.store.load();
var grid2 = new Pf.classes.student();
var panel = new Ext.TabPanel({
autoScroll : true,
@@ -12,10 +12,15 @@ Pf.classes.student = Ext.extend(Ext.grid.EditorGridPanel,{
initStore: function(){
var store = new Ext.data.JsonStore({
fields: [
-
+ "name",
+ "number",
+ "sex",
+ "phone",
+ "home",
+ "class_name",
],
- root: 'content',
- url: 'store_url',
+ root: 'root',
+ url: '/students/get_all_students.json',
totalProperty:'total',
method:'GET',
});
@@ -24,12 +29,12 @@ Pf.classes.student = Ext.extend(Ext.grid.EditorGridPanel,{
initCm: function(){
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
- { header: '学号', sortable: true, dataIndex: '',editor:new Ext.form.TextField()},
- { header: '姓名', sortable: true, dataIndex: '',editor:new Ext.form.TextField()},
- { header: '班级', sortable: true, dataIndex: '',editor:new Ext.form.TextField()},
- { header: '性别', sortable: true, dataIndex: '',editor:new Ext.form.TextField()},
- { header: '联系电话', sortable: true, dataIndex: '',editor:new Ext.form.TextField()},
- { header: '住址', sortable: true, dataIndex: '',editor:new Ext.form.TextField()},
+ { header: '学号', sortable: true, dataIndex: 'number',editor:new Ext.form.TextField()},
+ { header: '姓名', sortable: true, dataIndex: 'name',editor:new Ext.form.TextField()},
+ { header: '班级', sortable: true, dataIndex: 'class_name',editor:new Ext.form.TextField()},
+ { header: '性别', sortable: true, dataIndex: 'sex',editor:new Ext.form.TextField()},
+ { header: '联系电话', sortable: true, dataIndex: 'phone',editor:new Ext.form.TextField()},
+ { header: '住址', sortable: true, dataIndex: 'home',editor:new Ext.form.TextField()},
]);
return cm;
},

0 comments on commit ac792ce

Please sign in to comment.