user1391869
user1391869

Reputation:

How to set dynamic url in sencha touch using store?

I am new for this platform, Now i am unable to set dyanimic url using category id and token.

What i want: I have list different items, which have different ids but same token, token(tokent is same one user) getting from login phase. I want to get value accorading to category id from the server. Here is the my model:

Ext.define('MyApp.model.CategoryDisplayModelMenu', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
           /*'cat_id',*/
           'category',
           'name',
        ],

        belongsTo: "MyApp.model.CategoryDisplayModel"
    }
});

and another related model is:

Ext.define('MyApp.model.CategoryDisplayModel', {
    extend: 'Ext.data.Model',
    requires: ['MyApp.model.CategoryDisplayModelMenu'],
    config: {
        fields: [
         {name:'data', mapping: 'data'},
            {name:'name'},
            {name: 'category'},
            {name: 'author'},
        ],
    }
});

What i am set in store, but could not work:

Ext.define('MyApp.store.CategoryValueStore', {
    extend: 'Ext.data.Store',
    alias: 'store.CategoryValueStore',

    requires: [
        'MyApp.model.CategoryDisplayModel'
    ],
     config: {
        model: 'MyApp.model.CategoryDisplayModel',
        storeId: 'categoriesvaluestore',

    proxy: {
        type: 'rest',
        url: 'http://horror/myapp/api/word/searched_words/catID/'+ 1+'/'+ SDSILLYTOKEN+'/'+650773253e7f157a93c53d47a866204dedc7c363,
        noCache: false,           
        reader: {
            type: 'json',
            rootProperty: ''
        }  }    }
});

How to set above url, dynamic, cat id and token may be differnt.

But it works when i set these in store

Ext.define('MyApp.store.ArchitectureDisplayStore',{
extend: 'Ext.data.Store', 
requires:[
'MyApp.view.Main'
],
config:
{
    model: 'MyApp.model.CategoryDisplayModel',
    autoLoad:true,
    id:'Category',
    proxy:
    {
        type: 'ajax',
        url : 'http://horror/myapp/api/word/searched_words/catID/1/SDSILLYTOKEN/650773253e7f157a93c53d47a866204dedc7c363', // file containing json data
          reader:
        {
                rootProperty:''
        }  } }
});

In View , I set getting value on list like this:

Ext.define("MyApp.view.ArchitectureDisplayMain", {
  extend: 'Ext.Container',  
  alias: "widget.architecturewords", 

  config: {
   {      

       xtype: 'list',
       scrollable: true,       
       itemId: 'demolist',          
            itemTpl: [
            '<div><tpl for="data"><ul class="catList">{name} -test- {category}</ul> <ul>{author}</ul></tpl></div>'
            ],
            store: 'categoriesvaluestore',
          }
          }
          });

My category display model:

  Ext.define('MyApp.model.CategoryModelMenu', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            'cat_id',
           'category_name',
        ],

        belongsTo: "MyApp.model.CategoryModel"
    }
}); 

and

Ext.define('MyApp.model.CategoryModel', {
    extend: 'Ext.data.Model',

    requires: ['MyApp.model.CategoryModelMenu'],

    config: {
        fields: [
         {name:'data', mapping: 'data'},
              {name: 'cat_id'},
              {name: 'category_name'},
        ],
    }
});

EDIT:

Ext.define('MyApp.view.Category', {
    extend: 'Ext.List',
   alias: "widget.category", 
    config: {
        title: 'Stores',
        cls: 'category-data',
        scrollable: false,
        store: 'CategoryStore',
        itemTpl: [

        '<div class="categoryListings">',
          '<tpl for="data">',
          '<span onClick="catOption({cat_id})">{category_name}</span> ',
          '</tpl>',
          '</div>',

        ].join('')
    }
  //}
});

function catOption(id){

  console.log("ID--"+id);
var  tokan= '650773253e7f157a93c53d47a866204dedc7c363';
     Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);  
         Ext.Viewport.add([

             { xtype: 'wordsview' }

             ]);  

} and others

In wordsview, I like to display respective words of clicked category.

It is ok, when click this, first item of id p1, it shows next view.

Please tell me, How to get dynamic data accorading to its category id and token. please give some solution.Thank you advance.

Upvotes: 1

Views: 2565

Answers (2)

Viswa
Viswa

Reputation: 3211

If i understood you correctly

Let's say if you have category id and token in localStorage.

You can do like this

proxy:
{
   type: 'ajax',
   url : 'http://horror/myapp/api/word/searched_words/catID/'+localStorage.catId+'/SDSILLYTOKEN/'+localStorage.token,
     reader:{
       rootProperty:''
     }  
} 

OR

Do as @Alex posted. That is better way.. Like

function catOption(id){
  console.log("ID--"+id);
  var  token= '650773253e7f157a93c53d47a866204dedc7c363';

    var url = 'http://horror/myapp/api/word/searched_words/catID/'+id+'/SDSILLYTOKEN/'+token;

    Ext.getStore("categoriesvaluestore").getProxy().setUrl(url); 
    Ext.getStore("categoriesvaluestore").load();

     Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);  
     Ext.Viewport.add({ xtype: 'wordsview' });  
}

Upvotes: 1

Alex
Alex

Reputation: 1394

When accessing your Store from your View or anywhere else, you can dinamically change the Url this way:

var stProxy = Ext.StoreMgr.get("myStore").getProxy();
stProxy.setUrl("http://the.new.url");
Ext.StoreMgr.set("myStore").setProxy(stProxy);

--

The particular problem in your scenario is that you may have to populate your list manually. If you want a List to include the result of calling the same Store with different URLs, I suggest to build a new local Store loading the content of all iterations. Then make the List "store" property be this global Store.

Upvotes: 1

Related Questions