Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6899105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:22:48+00:00 2026-05-27T07:22:48+00:00

I have read many questions/answers and tutorials and I still fail to implement hierarchical

  • 0

I have read many questions/answers and tutorials and I still fail to implement hierarchical model in Sencha Touch. The root model is Tag. Each Tag has many Items. Here is my model:

The root tag:

app.models.Tag = Ext.regModel("Tag", {
    fields : [ {
        name : "id",
        type : "int"
    }, {
        name : "name",
        type : "string"
    }], 
    associations : {
        type : "hasMany",
        model : "TagItem", 
        name : "items"
    }
});

Adjected TagItem

app.models.TagItem = Ext.regModel("TagItem", {
    fields : [ {
        name : "id",
        type : "int"
    }, {
        name : "title",
        type : "string"
    }, {
        name : "type", 
        type : "string"
    }, {
        name : "tag_id", 
        type : "int"
    }], 
    associations : {
        belongsTo : {
            model : "Tag",
            name : "items"
        }
    }
});

TagStore:

app.stores.tagItems = new Ext.data.Store({
    model : "app.models.TagItem",
    proxy : {
        type : 'scripttag',
        root : 'items',
        url : 'http://www.s-lab.cz/ios/api/tags.php'
    }
});

Tags:

app.stores.tags = new Ext.data.Store({
    model : "app.models.TagItems",
    proxy : {
        type : 'scripttag',
        url : 'http://www.s-lab.cz/ios/api/tags.php'
    }
});

When I try to load items from the store I get:

Uncaught TypeError: Cannot call method ‘read’ of undefined

My JSON looks like this:

stcCallback1005([
 {
    "id":1,
    "name":"Doktor",
    "url":"doktor",
    "items":[
       {
          "type":"video",
          "id":1,
          "title":"First tag item",
          "tag_id":1
       },
       {
          "type":"article",
          "id":1,
          "title":"Second tag item - article",
          "tag_id":1
       },
       {
          "type":"article",
          "id":2,
          "title":"Third tag item - article",
          "tag_id":1
       },
       {
          "type":"video",
          "id":2,
          "title":"Fourth tag item",
          "tag_id":1
       }
    ]
 },
 {
    "id":2,
    "name":"Nemocnice",
    "url":"nemocnice"
 },
 {
    "id":3,
    "name":"Sestra",
    "url":"sestra"
     }
  ]);

Update:

I changed the code with suggestions and the resulting JSON is like this:

stcCallback1005({
    "results": [{
        "id": 1,
        "name": "Doktor",
        "url": "doktor",
        "items": [{
            "type": "video",
            "id": 1,
            "title": "First tag item",
            "tag_id": 1
        }, {
            "type": "article",
            "id": 1,
            "title": "Second tag item - article",
            "tag_id": 1
        }, {
            "type": "article",
            "id": 2,
            "title": "Third tag item - article",
            "tag_id": 1
        }, {
            "type": "video",
            "id": 2,
            "title": "Fourth tag item",
            "tag_id": 1
        }]
    }, {
        "id": 2,
        "name": "Nemocnice",
        "url": "nemocnice"
    }, {
        "id": 3,
        "name": "Sestra",
        "url": "sestra"
    }]
});

But still I’m not able to access the subsequent items: app.stores.tags.getAt(0) works, but app.stores.tags.getAt(0).TagItems() does not (neither app.stores.tags.getAt(0).items or app.stores.tags.getAt(0).items() does). And also my template doesn’t render correctly: <tpl for=".">{name}<ul><tpl for="items"><li>{title} ({type})</li></tpl></ul></tpl>

Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:22:48+00:00Added an answer on May 27, 2026 at 7:22 am

    I think you don’t need to assign a variable for model registration.

    Ext.regModel("Tag", {
        fields : [ {
            name : "id",
            type : "int"
        }, {
            name : "name",
            type : "string"
        }], 
        associations : {
            type : "hasMany",
            model : "TagItem", 
            name : "items"
        }
    });
    

    So;

    Ext.regModel("TagItem", {
        fields : [ {
            name : "id",
            type : "int"
        }, {
            name : "title",
            type : "string"
        }, {
            name : "type", 
            type : "string"
        }, {
            name : "tag_id", 
            type : "int"
        }], 
        associations : {
            belongsTo : {
                model : "Tag",
                name : "items"
            }
        }
    });
    

    Add reader to json and correct registered model names.

    TagStore:

    app.stores.tagItems = new Ext.data.Store({
        model : "TagItem", //Use registered name
        proxy : {
            type : 'scripttag',
            url : 'http://www.s-lab.cz/ios/api/tags.php'
    
                       reader: { //add reader to read from json
                          type: 'json',
                          root: 'results'
                       }
        }
    });
    

    Tags:

    app.stores.tags = new Ext.data.Store({
        model : "Tag", //Use registered name
        proxy : {
            type : 'scripttag',
            url : 'http://www.s-lab.cz/ios/api/tags.php'
                       reader: { //add reader to read from json
                          type: 'json',
                         root: 'results'
                       }
        }
    });
    

    And finally maybe you need to change your json format in tags.php as;

    {"results":[
     {
        "id":1,
        "name":"Doktor",
        "url":"doktor",
        "items":[
           {
              "type":"video",
              "id":1,
              "title":"First tag item",
              "tag_id":1
           },
           {
              "type":"article",
              "id":1,
              "title":"Second tag item - article",
              "tag_id":1
           },
           {
              "type":"article",
              "id":2,
              "title":"Third tag item - article",
              "tag_id":1
           },
           {
              "type":"video",
              "id":2,
              "title":"Fourth tag item",
              "tag_id":1
           }
        ]
     },
     {
        "id":2,
        "name":"Nemocnice",
        "url":"nemocnice"
     },
     {
        "id":3,
        "name":"Sestra",
        "url":"sestra"
         }
      ]
    }
    

    I hope it works or helps to correct your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read many of the good questions and answers around multi-core programming how-tos
I have read many questions and answers, but I couldn´t find solution for my
I have read many suggested questions, but still cannot find out the answer. I
I have read many questions about Android, J2ME and RecordStore , but I still
I have read many articles regarding layout, but I am still quitely confused. My
I've read many of the non-nullable questions and answers. It looks like the best
I have read many posts on here regarding this issue; The answers of 'Why
I have read a few similar questions and answers, but none completely address my
I have problem with one-to-many mapping. Two tables questions(PK(id), text) and answers(PK(id, questionId), text)
Am tearing my hair out here. Have read many examples which describe how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.