ExtJS-Data Package (数据处理包)
Posted 重庆熊猫
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ExtJS-Data Package (数据处理包)相关的知识,希望对你有一定的参考价值。
更新记录
2023年3月9日 发布。
ExtJS教程汇总:https://www.cnblogs.com/cqpanda/p/16328016.html
官方文档:https://docs.sencha.com/extjs/7.6.0/classic/Ext.data.schema.Association.html
说明
在ExtJS中,可以设置模型与模型之间的关系,如一对多、多对一或一对一关系。
定义Model关系的方式:
1、使用hasMany/hasOne/belongsTo配置项即可。比如:
hasMany: model: \'xx\', name: \'\',
hasOne: model: \'xx\', name: \'\',
belongsTo: \'\',
2、除了使用直接配置项,还可以使用associations配置项,比如:
associations: type: \'hasOne\', model: \'xxx\', name: \'\'
一对多
说明
使用hashMany配置项即可。
实例:一个用户有多个文章数据
Ext.define(\'User\',
extend: \'Ext.data.Model\',
field: [ \'id\' ],
hasMany: [
//在用户模型与文章模型之间建立一对多的关联关系
model: \'Article\', name: \'articles\' ,
]
);
Ext.define(\'Article\',
extend: \'Ext.data.Model\',
field: [ \'id\' ],
//文章对应属于一个用户
belongsTo: \'User\',
);
实例:一个用户有多条评论数据
Ext.define(\'User\',
extend: \'Ext.data.Model\',
field: [ \'id\' ],
hasMany: [
//在用户模型与评论模型之间建立一对多的关联关系
model: \'Comment\', name: \'comments\'
]
);
实例: 一篇文章有多条评论数据
Ext.define(\'Article\',
extend: \'Ext.data.Model\',
field: [ \'id\' ],
//在文章模型与评论模型之间建立一对多的关联关系
hasMany: model: \'Comment\', name: \'comments\'
);
Ext.define(\'Comment\',
extend: \'Ext.data.Model\',
field: [ \'id\' ],
//评论属于文章
belongsTo: \'Article\',
);
(待优化)实例:模型实例化(一对一关联,One-to-one associations)
//被引用的Model
Ext.define(\'Myapp.model.Contract\',
extend:\'Ext.data.Model\',
idProperty:\'id \',
fields: [
name: \'id\', type: \'int\' ,
name: \'contractId\', type: \'string\',
name: \'documentType\', type: \'string\'
]
);
//引用其他Model的Model
Ext.define(\'Myapp.model.Customer\',
extend:\'Ext.data.Model\',
requires: [ \'Myapp.model.Contract\'],
idProperty:\'id \',fields:[
name: \'id\', type: \'int\',
name: \'name\' , type: \'string\',
name: \'phone\' , type: \'string\',
name: \'website\' , type: \'string\',
name: \'status\' , type: \'string\',
name: \'clientSince\' , type: \'date\', dateFormat: \'Y-m-d H:i\',
name: \'contractInfo\' , reference: \'Contract\', unique:true
]
);
//创建Model实例
let myclient = Ext.create(\'Myapp.model.Customer\',
id: 10001,
name: \'Acme corp\',
phone: \'+52-01-55-4444-3210\',
website: \'www.acmecorp.com\',
status: \'Active\',
clientSince: \'2010-01-01 14:35\',
//为引用的Model赋值
contractInfo:
id:444,
contractId:\'ct-001-444\',
documentType:\'PDF\'
);
(待优化)实例:模型实例化(一对一关联,One-to-one associations)
//被引用的Model
Ext.define(\'Myapp.model.Contract\',
extend:\'Ext.data.Model\',
idProperty:\'id \',
fields: [
name: \'id\', type: \'int\' ,
name: \'contractId\', type: \'string\',
name: \'documentType\', type: \'string\'
]
);
//引用其他Model的Model
Ext.define(\'Myapp.model.Customer\',
extend:\'Ext.data.Model\',
requires: [ \'Myapp.model.Contract\'],
idProperty:\'id \',fields:[
name: \'id\', type: \'int\',
name: \'name\' , type: \'string\',
name: \'phone\' , type: \'string\',
name: \'website\' , type: \'string\',
name: \'status\' , type: \'string\',
name: \'clientSince\' , type: \'date\', dateFormat: \'Y-m-d H:i\',
name: \'contractInfo\' , reference: \'Contract\', unique:true
]
);
//创建Model实例
let myclient = Ext.create(\'Myapp.model.Customer\',
id: 10001,
name: \'Acme corp\',
phone: \'+52-01-55-4444-3210\',
website: \'www.acmecorp.com\',
status: \'Active\',
clientSince: \'2010-01-01 14:35\',
//为引用的Model赋值
contractInfo:
id:444,
contractId:\'ct-001-444\',
documentType:\'PDF\'
);
(待优化) 实例:一对多关联(One-to-many associations)
Ext.define(\'Myapp.model.Client\',
extend:\'Ext.data.Model\',
//加载依赖的Model
requires: [\'Myapp.model.Employee\'],
idProperty:\'id \',
fields:[.... ],
//配置一对多
hasMany:
model:\'Myapp.model.Employee\',
name:\'employees\',
associationKey: \'employees\'
);
//被引用的Model
Ext.define(\'Myapp.model.Employee\',
extend:\'Ext.data.Model\',
idProperty:\'id\',
fields:[
name: \'id\', type: \'int\' ,
name: \'clientid\' , type: \'int\',
name: \'name\' , type: \'string\',
name: \'phone\' , type: \'string\',
name: \'email\' , type: \'string\',
name: \'gender\' , type: \'string\'
]
);
//model实例化
let myclient = Ext.create(\'Myapp.model.ClientWithContacts\',
id: 10001,
name: \'Acme corp\',
phone: \'+52-01-55-4444-3210\',
website: \'www.acmecorp.com\',
status: \'Active\',
clientSince: \'2010-01-01 14:35\'
);
//给Model引用的Model添加数据
myclient.employees().add(
id:101,
clientId:10001,
name:\'Juan Perez\',
phone:\'+52-05-2222-333\',
email:\'juan@test.com\',
gender:\'male\'
,
id:102,
clientId:10001,
name:\'Sonia Sanchez\',
phone:\'+52-05-1111-444\',
email:\'sonia@test.com\',
gender:\'female\'
);
//遍历读取被引用的Model
myclient.employees().each(function(record)
console.log(record.get(\'name\') + \' - \' + record.get(\'email\') );
);
本文来自博客园,作者:重庆熊猫,转载请注明原文链接:https://www.cnblogs.com/cqpanda/p/17198416.html
创建ROS的Package(功能包)
本文讲如何用catkin创建一个ROS的package
1. catkin package的组成:一定要包含CMakeLists.txt及package.xml文件
my_package/ CMakeLists.txt package.xml
此外,每个package必须要有他自己的文件夹。
2. 推荐使用catkin workspace来处理catkin package
workspace_folder/ -- WORKSPACE src/ -- SOURCE SPACE CMakeLists.txt -- ‘Toplevel‘ CMake file, provided by catkin package_1/ CMakeLists.txt -- CMakeLists.txt file for package_1 package.xml -- Package manifest for package_1 ... package_n/ CMakeLists.txt -- CMakeLists.txt file for package_n package.xml -- Package manifest for package_n
3. 创建catkin package
使用catkin_create_pkg脚本来创建新的catkin package:
(1)切换source space目录至之前创建的catkin workspace
$ cd ~/catkin_ws/src
(2)用catkin_create_pkg创建一个catkin package,名字是beginner_tutorials,且依赖于已有的功能包std_msgs,roscpp,rospy,后者称为dependency
$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
4. build 这个catkin workspace, source 这个setup文件
build方法:
$ cd ~/catkin_ws $ catkin_make
source方法:
$ . ~/catkin_ws/devel/setup.bash
5. package dependencies
(1)用rospack查看1阶dependencies:
$ rospack depends1 beginner_tutorials
package.xml中储存了package的dependencies信息
$ roscd beginner_tutorials $ cat package.xml
(2)用rospack查看间接(高阶)的dependencies:
$ rospack depends beginner_tutorials
6. customize(自定义、定制) package
6.1 自定义package.xml
(1) 描述标签(description tag):尽可能短
5 <description>The beginner_tutorials package</description>
(2)Maintainer 标签:必须有,而且非常重要,至少要有一条。作用是让别人知道有关这个package该联系谁。
Toggle line numbers 7 <!-- One maintainer tag required, multiple allowed, one person per tag --> 8 <!-- Example: --> 9 <!-- <maintainer email="[email protected]">Jane Doe</maintainer> --> 10 <maintainer email="[email protected]">user</maintainer>
(3)许可证标签(license tag):有很多开源许可证,我们这里使用BSD,因为许多ROS核心部件都是用的它。
12 <!-- One license tag required, multiple allowed, one license per tag --> 13 <!-- Commonly used license strings: --> 14 <!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 --> 15 <license>TODO</license>
(4)dependencies标签: dependencies标签可分为build_depend, buildtool_depend, exec_depend, test_depend。因为我们使用了std_msgs, roscpp, and rospy,所以该标签应为:
27 <!-- The *_depend tags are used to specify dependencies --> 28 <!-- Dependencies can be catkin packages or system dependencies --> 29 <!-- Examples: --> 30 <!-- Use build_depend for packages you need at compile time: --> 31 <!-- <build_depend>genmsg</build_depend> --> 32 <!-- Use buildtool_depend for build tool packages: --> 33 <!-- <buildtool_depend>catkin</buildtool_depend> --> 34 <!-- Use exec_depend for packages you need at runtime: --> 35 <!-- <exec_depend>python-yaml</exec_depend> --> 36 <!-- Use test_depend for packages you need only for testing: --> 37 <!-- <test_depend>gtest</test_depend> --> 38 <buildtool_depend>catkin</buildtool_depend> 39 <build_depend>roscpp</build_depend> 40 <build_depend>rospy</build_depend> 41 <build_depend>std_msgs</build_depend>
我们希望在build和run的时候使用所有特定的dependencies,因此我们还要增加exec_depend标签,最后如下:
12 <buildtool_depend>catkin</buildtool_depend> 13 14 <build_depend>roscpp</build_depend> 15 <build_depend>rospy</build_depend> 16 <build_depend>std_msgs</build_depend> 17 18 <exec_depend>roscpp</exec_depend> 19 <exec_depend>rospy</exec_depend> 20 <exec_depend>std_msgs</exec_depend>
(5) 最终的package.xml:下面是不含有评论和未使用tag的package.xml文件,非常concise(简明)
<?xml version="1.0"?> <package format="2"> <name>beginner_tutorials</name> <version>0.1.0</version> <description>The beginner_tutorials package</description> <maintainer email="[email protected]">Your Name</maintainer> <license>BSD</license> <url type="website">http://wiki.ros.org/beginner_tutorials</url> <author email="[email protected]">Jane Doe</author> <buildtool_depend>catkin</buildtool_depend> <build_depend>roscpp</build_depend> <build_depend>rospy</build_depend> <build_depend>std_msgs</build_depend> <exec_depend>roscpp</exec_depend> <exec_depend>rospy</exec_depend> <exec_depend>std_msgs</exec_depend> </package>
6.2 自定义CMakeLists.txt
以上是关于ExtJS-Data Package (数据处理包)的主要内容,如果未能解决你的问题,请参考以下文章