1. #1
    Ext User
    Join Date
    Apr 2007
    Posts
    4
    Vote Rating
    0
    dwebsubmit is on a distinguished road

      0  

    Default Nested View Objects/Nested Xml collections

    Nested View Objects/Nested Xml collections


    2 questions in one,
    Can you use the xmlReader to read something that looks like this:
    Code:
    <items>
      <item>
        <title>my title</title>
        <description>This would be a description</description>
        <tags>
          <tag>
            <name>first</name>
            <name>second</name>
            <name>third</name>
          </tag>
        </tags>
      </item>
      <item>
        <title>my title</title>
        <description>This would be a description</description>
        <tags>
          <tag>
            <name>first</name>
            <name>second</name>
            <name>third</name>
          </tag>
        </tags>
      </item>
    </items>
    So that it would return
    record.data.title => 'my title'
    and
    record.data.tags[0].name => "first"


    second part to the question is: can you nest views/templates?

    BTW, I am using the 1.0 b2 version

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    4
    tryanDLS is on a distinguished road

      0  

    Default


    1. Look at xml-grid example. You can do xpath type field mapping.

    2. Not sure what you're looking for with nesting. You might look at the MasterTemplate class

  3. #3
    Ext User
    Join Date
    Apr 2007
    Posts
    4
    Vote Rating
    0
    dwebsubmit is on a distinguished road

      0  

    Default


    are you saying that if I do something like this
    Code:
    var dsr = new Ext.data.XmlReader({
    record: 'item',
    },[
    {title: 'title',
    description: 'description',
    tagName: 'name', mapping: 'item > tag'}
    ]
    });
    This will automatically group those tag/names values under a single record?

    I am trying to get those nested values as an array of elements for the item parent.
    So that when I select one of them I can tell how many and which tag.name are associated with it.

    record.data.tags[0].name #=> first

    I am looking to create a nested grid or nested view.

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    4
    tryanDLS is on a distinguished road

      0  

    Default


    No I meant you could navigate down to deeper single attributes/elements. There's no 'grouping' functionality.

  5. #5
    Ext User
    Join Date
    Apr 2007
    Posts
    4
    Vote Rating
    0
    dwebsubmit is on a distinguished road

      0  

    Default


    Well then
    I guess I am going to vote it as a feature request.

    Has anybody requested it before me?

  6. #6
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    You can do it with the latest JsonReader.

    Json data block:

    Code:
    {
        items: [
            {title: "my title", description:"my desc", name: ["firstName", "secondName", "third name"]}
        ],
    Code:
        var dsr = new Ext.data.XmlReader({
            record: 'item',
        },
        [
            {title: 'title',
            description: 'description',
            tagName: 'name', mapping: 'name[0] + " " + obj.name[1] + " " + obj.name[2]'}
        ]
    });
    The JsonReader creates dynamic accessor functions into which it passes the row object as the parameter "obj". It uses the expression

    Code:
    "obj." + mappingExpression
    to create the function source code to extract the data, so you can use that to create complex accessors.

  7. #7
    Ext User
    Join Date
    Jul 2007
    Posts
    1
    Vote Rating
    0
    navamara is on a distinguished road

      0  

    Question Nested XML question

    Nested XML question


    Hi,
    I have a similar situation to create mapping for nested xml data using XMLReader, I need to read nested xml data.
    sample xml is as below....

    <ComponentVO>
    <id>112</id>
    <name>Java</name>
    <version>1.6</version>
    <commercialComponent>true</commercialComponent>
    <openSourceComponent>true</openSourceComponent>
    <containsCrypto>false</containsCrypto>
    <textsOfLicences>
    <TextOfLicenseVO>
    <id>113</id>
    <text>License Information 2</text>
    </TextOfLicenseVO>
    <TextOfLicenseVO>
    <id>114</id>
    <text>License Information 1</text>
    </TextOfLicenseVO>
    </textsOfLicences>
    <description>Java 1.6 description</description>
    <notes/>
    </ComponentVO>


    Iam not sure about creating a mapping for TextofLicenseVO.
    Here is the store definition

    var comp_data = new Ext.data.Store({
    // load using HTTP
    proxy: new Ext.data.HttpProxy({url: '/myapp/ComponentServiceServlet?action=load&cid=' + selprodId}),
    reader: new Ext.data.XmlReader({
    record: '',
    id: 'id'
    },[
    {name: 'id'},'name','version','release','supplier','description',
    'commercialComponent','openSourceComponent','containsCrypto',
    {name: 'licenseText', mapping:'TextOfLicenseVO > text'}
    ])
    });


    licenseText gives me only the last instance. How to give the mapping for TextOfLicenseVO so that i can access all the values under this tag.
    Thanks
    -navamara

  8. #8
    Sencha User Iveco's Avatar
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    70
    Vote Rating
    1
    Iveco is on a distinguished road

      0  

    Default


    Quote Originally Posted by Animal View Post
    You can do it with the latest JsonReader.

    Json data block:

    Code:
    {
        items: [
            {title: "my title", description:"my desc", name: ["firstName", "secondName", "third name"]}
        ],
    Code:
        var dsr = new Ext.data.XmlReader({
            record: 'item',
        },
        [
            {title: 'title',
            description: 'description',
            tagName: 'name', mapping: 'name[0] + " " + obj.name[1] + " " + obj.name[2]'}
        ]
    });
    The JsonReader creates dynamic accessor functions into which it passes the row object as the parameter "obj". It uses the expression

    Code:
    "obj." + mappingExpression
    to create the function source code to extract the data, so you can use that to create complex accessors.
    I need this functionality for XMLReader in ExtJS1.1.1

    How can I map nested elements to one record?
    I tried mappings like:

    {name: 'mydata', mapping: 'type//*@data'}
    {name: 'mydata', mapping: 'type/*@data'}
    {name: 'mydata', mapping: 'type/nested*@data'}
    {name: 'mydata', mapping: 'type/nested@data'} // only first element is read... :-(

    XML:
    <root>
    <record> <-- this is my record: 'record' in XMLReader (top mappings (mydata) are relative to this element)
    <type name="A">
    <nested data="A" />
    <nested data="B" />
    </type>
    </record>
    </root>

    Thanks...

    edit: also tried mapping "//@data" or '//nested[@data]' which should get any data attribute element, doesn't matter where it is, but still my store won't add all data to its record. I think the data store isn't clever enough to pull the data into the record as an array or sth. like that. (Is this correct, and when not how can I tell the grid to use also the array data e.g.).

    Anyone has any idea / tip how to solve this?
    Last edited by Iveco; 2 Oct 2007 at 6:49 AM. Reason: more information

  9. #9
    Sencha User Iveco's Avatar
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    70
    Vote Rating
    1
    Iveco is on a distinguished road

      0  

    Default


    I solved this by using a second datastore which is using the root element id: <name> so I can loop the multiply elements and I use store.filterBy(myfunction) to only get the wished values for my detail grid.

    If anyone has an idea to how to solve this with one datastore would be great.

  10. #10
    Sencha Premium Member
    Join Date
    Jul 2007
    Location
    Alexandria, VA
    Posts
    3
    Vote Rating
    0
    Bill Sheppard is on a distinguished road

      0  

    Default


    Hi Iveco,

    Could you please post your 2 store solution?

    Thanks,

    --Bill