修改Model中hasMany中自动生成的属性值
2012-07-15 11:27
113 查看
在学习EXTJS的文档是,在测试《The Data Package》中的例子时,文中讲到Model中的hasMany自动生成的是一个Store对象的引用,如hasMany: 'Post',自动生成的是post()方法,实际上指向的Post的Store引用。自动生成的Store在向后台请求数据时的Get参数为:posts/?_dc=1342322365337&limit=25&page=1&start=0&filter=%5B%7B%22property%22%3A%22user_id%22%2C%22value%22%3A1%7D%5D,其中limit的值为25,这是默认值,如果想要修改这个默认值,可以调用:user.posts().proxy.setExtraParam("limit", 100);进行修改。完整代码如下:
/**
* @example Lazy Associations
*
* This example demonstrates lazy loading of a {@link Ext.data.Model}'s associations only when requested.
* a `User` model is loaded, then a separate request is made for the `User`'s associated `Post`s
* See console for output.
*/
// define the User model
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'age', 'gender'],
proxy: {
type: 'rest',
url : 'data/users',
reader: {
type: 'json',
root: 'users'
}
},
hasMany: 'Post' // shorthand for {model: 'Post', name: 'posts'}
});
//define the Post model
Ext.define('Post', {
extend: 'Ext.data.Model',
fields: ['id', 'user_id', 'title', 'body'],
proxy: {
type: 'rest',
url : 'data/posts',
reader: {
type: 'json',
root: 'posts'
}
},
belongsTo: 'User',
hasMany: {model: 'Comment', name: 'comments'}
});
//define the Comment model
Ext.define('Comment', {
extend: 'Ext.data.Model',
fields: ['id', 'post_id', 'name', 'message'],
belongsTo: 'Post'
});
Ext.require('Ext.data.Store');
Ext.onReady(function () {
// Loads User with ID 1 User's Proxy
User.load(1, {
success: function (user) {
console.log("User: " + user.get('name'));
// Loads posts for user 1 using Post's Proxy
user.posts().proxy.setExtraParam("limit", 100);
user.posts().load({
callback: function (posts, operation) {
Ext.each(posts, function (post) {
console.log("Comments for post: " + post.get('title'));
post.comments().each(function (comment) {
console.log(comment.get('message'));
});
});
}
});
}
});
});
/**
* @example Lazy Associations
*
* This example demonstrates lazy loading of a {@link Ext.data.Model}'s associations only when requested.
* a `User` model is loaded, then a separate request is made for the `User`'s associated `Post`s
* See console for output.
*/
// define the User model
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'age', 'gender'],
proxy: {
type: 'rest',
url : 'data/users',
reader: {
type: 'json',
root: 'users'
}
},
hasMany: 'Post' // shorthand for {model: 'Post', name: 'posts'}
});
//define the Post model
Ext.define('Post', {
extend: 'Ext.data.Model',
fields: ['id', 'user_id', 'title', 'body'],
proxy: {
type: 'rest',
url : 'data/posts',
reader: {
type: 'json',
root: 'posts'
}
},
belongsTo: 'User',
hasMany: {model: 'Comment', name: 'comments'}
});
//define the Comment model
Ext.define('Comment', {
extend: 'Ext.data.Model',
fields: ['id', 'post_id', 'name', 'message'],
belongsTo: 'Post'
});
Ext.require('Ext.data.Store');
Ext.onReady(function () {
// Loads User with ID 1 User's Proxy
User.load(1, {
success: function (user) {
console.log("User: " + user.get('name'));
// Loads posts for user 1 using Post's Proxy
user.posts().proxy.setExtraParam("limit", 100);
user.posts().load({
callback: function (posts, operation) {
Ext.each(posts, function (post) {
console.log("Comments for post: " + post.get('title'));
post.comments().each(function (comment) {
console.log(comment.get('message'));
});
});
}
});
}
});
});
相关文章推荐
- Spring3 Mybatis3 freemarker 自动生成对应表的model、mapper、service、controller并自动修改mybatis配置文件
- .Net中自动生成Model字段修改日志内容
- 修改idea自动生成在C盘的文件路径,以免电脑越用越卡
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- IntelliJ IDEA 中怎么修改新建文件时,自动生成的注释的user的默认值
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转) 出处:http://www.cnblogs.com/lichenwei/p/4145696.html
- MyBatis-- maven自动生成映射文件及classPathEntry 路径修改
- 修改eclipse自动生成的comments中的author名字
- 【Maven学习(七)】----基于Mybatis-Generator自动生成Dao、Model、Mapping文件
- 使用Mybatis-Generator自动生成相应的Dao、Model、Mapping相关文件
- ssm中自动生成model和service中文件的方法
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关
- Mybatis-Generator自动生成Dao、Model、Mapping文件
- Maven中使用MyBatis自动生成model实体、dao、XML映射文件
- mybaits generator自动生成model、xml、dao
- windows下Android利用ant自动编译、修改配置文件、批量多渠道,打包生成apk文件
- 数据库操作-----开源第三方---greendao-----所有的dao和model自动生成,不用写,懒人必备
- Eclipse自动生成注释,修改注释模板
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- IOS 利用Model 反射属性 自动 创建表 插入 查询 修改