我使用嵌套的 XML并使用’hasMany’解析它.如果有人能告诉我如何读取节点’ type‘的值,我将不胜感激.我可以轻松阅读属性’id’和使用映射的’val’,但我也想读取节点值,例如. 257411 i
< type id =“3”val =“0”> 257411
如果有人能提供合适的“映射”,我将不胜感激
XML数据:
<?xml version="1.0" encoding="ISO-8859-1"?>
<basics id="744" name="social">
<number>302221</number>
<types>
<type id="3" val="0">257411</type>
<type id="2" val="1081337">28213</type>
<type id="1" val="263258">8645</type>
<type id="5" val="0">3664</type>
<type id="4" val="0">2246</type>
<type id="9" val="0">1124</type>
<type id="10" val="0">918</type>
</types>
</basics>
型号基本
Ext.define( “ap3.model.Basic”,{
extend:“Ext.data.Model”,
config: {
fields: [
{name: 'id', mapping: '@id'},
{name: 'name', mapping: '@name'},
{name: 'number', mapping: 'number'}
],
associations: [
{
type: 'hasMany',
model: 'apv3.model.Type',
associationKey: 'types'
}]
}
});
型号类型
Ext.define( “ap3.model.Type”,{
extend:“Ext.data.Model”,
config: {
fields: [
{name: 'id', mapping: '@id'},
{name: 'val', mapping: '@val'},
{name: 'type', mapping: 'type'}
],
proxy: {
type: 'memory',
reader: {
type: 'xml',
record: 'type'
}
}
}
});
“mapping”也接受一个函数:{name: 'id', mapping: '@id'},
{name: 'name', mapping: '@name'},
{name: 'number', mapping: function (node) {
return (node.firstChild ? node.firstChild.nodeValue : null);
}}
