extjs模型定制mapp到xml

时间:2013-04-16 18:52:37

标签: extjs extjs4

我的模型有clientName model / AlertConfig.js:

Ext.define('ET.model.AlertConfig', {
    extend: 'Ext.data.Model',
    fields: [
             {name: 'id', type: 'string'},
             {name: 'clientName', type: 'string' },
             {name: 'description', type: 'string'},

传入的xml嵌入了整个客户端对象(如果存在):

<alertConfig>

    <commandType>D</commandType>
    <countThreshold>1</countThreshold>
    <description>Distributions that failed(all clients)</description>
    <id>2</id>
    <processTimeExceedsSec>0</processTimeExceedsSec>
    <status>3</status>
    <windowMinutes>120</windowMinutes>
  </alertConfig>
  <alertConfig>
    <client>
      <clientCategory>abc</clientCategory>
      <clientExtId>12345</clientExtId>
      <clientId>1</clientId>
      <clientName>MyClient1</clientName>
      <lastModified>2013-03-19T16:12:54.774-04:00</lastModified>
    </client>
    <commandType>R</commandType>
    <countThreshold>1</countThreshold>
    <description>Requests that failed</description>
    <id>3</id>
    <processTimeExceedsSec>0</processTimeExceedsSec>
    <status>3</status>
    <windowMinutes>120</windowMinutes>
  </alertConfig>

问题:

我只需要将alertConfig / client / clientName映射到模型中的clientName。我怎么能干净利落地做到这一点。有没有我可以提到这个xml路径的地方?

注意:在视图中,用户将看到ClientName(以及组合框中的所有客户端名称,用户可以选择&amp; update,使用不同的clientName作为警报。)

1 个答案:

答案 0 :(得分:0)

通过添加'/'

解决
Ext.define('ET.model.AlertConfig', {
    extend: 'Ext.data.Model',
    fields: [
             {name: 'id', type: 'string'},
             {name: 'clientId', mapping: 'client/clientId', type: 'int' }, 
             //not a field in erf.domain (but points to Client object)
             {name: 'clientName', mapping: 'client/clientName', type: 'string' }, // not a field in erf.domain
             {name: 'description', type: 'string'},