Cannot call method 'add' of undefined - sencha-touch

I have been try trying to make a dynamic carousal in sencha touch 2.1.1 which fetches the images from wordpress json data..
but when i call the load listener in store it gives and error .
I tasted this on another demo sencha app it was working fine there but when i add it here it shows up the error
Uncaught TypeError: Cannot call method 'add' of undefined
I am sharing my view,model,and store files here
Ext.define('Flugelsoft.view.Portfolio', {
extend:'Ext.Container' ,
xtype: 'portfolio',
fullscreen: true,
//store:'Portfolios',
requires: ['Flugelsoft.store.Portfolios', 'Ext.dataview.List', 'Ext.Img','Ext.carousel.Carousel'],
config: {
layout: {
type: 'fit'
},
items: [
{
xtype: "carousel",
id: 'carouselid'
}
]
}
});
store.js file
var token=localStorage.getItem("access_token");
Ext.define("Flugelsoft.store.Portfolios", {
extend: "Ext.data.Store",
requires: ["Ext.data.proxy.JsonP"],
config: {
model: "Flugelsoft.model.Portfolio",
autoLoad: true,
proxy: {
type: 'jsonp',
url: 'http://www.flugelsoft.net/?json=get_category_posts&category_id=2&access_token='+token,
reader: {
type: 'json',
rootProperty: 'posts'
}
},
}
});
var newPanel = Ext.create('Flugelsoft.store.Portfolios', {
listeners:{
load: function( me, records, successful, operation, eOpts ){
console.log("data loaded", records);
myCarousel = Ext.getCmp('carouselid');
for(var i=0; i<records.length; i++){
//THE ERROR IS GENERATING IN THIS LINE myCarousal.add
myCarousel.add({
xtype: 'image',
src: records[i].get('thumbnail')
});
}
}
}
});
Model.js file
Ext.define('Flugelsoft.model.Portfolio',{
extend:'Ext.data.Model',
config:{
fields: [{name: 'title', type: 'string'},{name: 'content', type: 'string'},{name:'thumbnail',type:'image/png'}]
}
});
Thank you in advance

First of all you should add Portfolio view in viewport before you invoke Ext.getCmp('carouselid');
Model
Ext.define('GoodNews.model.Portfolio',{
extend:'Ext.data.Model',
config:{
fields: [{name: 'title', type: 'string'},
{name: 'content', type: 'string'},
{name:'thumbnail',type:'string'}]
//thumbnail should be url for accessing picture from the server
}
});
Store
Ext.define("GoodNews.store.Portfolios", {
extend: "Ext.data.Store",
requires: ["Ext.data.proxy.JsonP"],
config: {
model: "GoodNews.model.Portfolio",
autoLoad: true,
proxy: {
type: 'jsonp',
url: 'http://www.flugelsoft.net/?json=get_category_posts&category_id=2&access_token='+token,
reader: {
type: 'json',
rootProperty: 'posts'
}
},
}
});
Add the portfolio
Ext.Viewport.add({xtype : 'portfolio'});
var newPanel = Ext.create('GoodNews.store.Portfolios', {
listeners:{
load: function( me, records, successful, operation, eOpts ){
console.log("data loaded", records);
myCarousel = Ext.getCmp('carouselid');
for(var i=0; i<records.length; i++){
myCarousel.add({
xtype: 'image',
src: records[i].get('thumbnail')
});
}
}
}
});
There is no image/png field type in sencha touch. following types only valid
auto: Object
boolean: Object
date: Object
float: Object
integer: Object
number: Object
string: Object

Related

How to get dynamically images from the store to the carousel sencha touch 2

Im trying to get images from a store , and control the number of the images , and show 12 images for each carousel ,all of that dynamically depending of the number of images on the store , if its up to ex: 12 ,to create an other carousel for the rest ...
but i've tried to begin with getting just images from the store and load it to the carousel , but my view is empty , nothing is diplaying ..
The model :
Ext.define("MyApp2.model.ApplicationModel", {
extend: "Ext.data.Model",
config: {
//type:'tree',
fields: [
{name: 'id', type: 'auto'},
{name: 'name', type: 'auto'},
{name:'icon',type:'image/jpg'}
]
}
});
The store :
var token=localStorage.getItem("access_token");
Ext.define("MyApp2.store.ApplicationStore", {
extend: "Ext.data.Store",
requires: ["Ext.data.proxy.JsonP"],
config: {
model: "MyApp2.model.ApplicationModel",
autoLoad: true,
id :'ApplicationStr',
proxy: {
type: 'jsonp',
url: 'http://mysite.com/api/applications?format=jsonp&access_token='+token,
reader: {
type: 'json',
rootProperty: 'applications'
}
}
}
});
var store = Ext.create('MyApp2.store.ApplicationStore');
store.getStore('ApplicationStr');
myCarousel = Ext.getCmp('carouselid');
store.each(function(record) {
myCarousel.add({
html: '<img src=' + record.get('icon') + '/>'
});
});
The view :
Ext.define('MyApp2.view.MainMenu', {
extend: 'Ext.Panel',
requires: ['Ext.TitleBar', 'MyApp2.store.ApplicationStore', 'Ext.dataview.List', 'Ext.Img'],
alias: 'widget.mainmenuview',
config: {
layout: {
type: 'fit'
},
items: [{
xtype: 'titlebar',
title: 'My Apps',
docked: 'top',
items: [
{
xtype: 'button',
text: 'Log Off',
itemId: 'logOffButton',
align: 'right'
}
]
},
{
xtype: "carousel",
id: 'carouselid'
}
],
listeners: [{
delegate: '#logOffButton',
event: 'tap',
fn: 'onLogOffButtonTap'
}]
},
onLogOffButtonTap: function() {
this.fireEvent('onSignOffCommand');
}
});
May be data in store is not loaded before you started iterating over it. To avoid such cases you should always use data in load events callback.
You can do 2 things, either add load listener in store and do carousel population in it
listeners:{
load: function( me, records, successful, operation, eOpts ){
console.log("data loaded", records);
myCarousel = Ext.getCmp('carouselid');
for(var i=0; i<records.length; i++){
myCarousel.add({
html: '<img src=' + records[i].get('icon') + '/>'
});
}
}
}
or you can call load manually when required and do it in callback like this:
store.load({
callback: function(records, operation, success) {
myCarousel = Ext.getCmp('carouselid');
for(var i=0; i<records.length; i++){
myCarousel.add({
html: '<img src=' + records[i].get('icon') + '/>'
});
}
},
scope: this
});

sencha touch~Reset extra param when load more event fire

I need to reassign extra param when load more even fire. But I dont have any idea
Here is my code
List.js
Ext.define('bluebutton.view.BlueButton.TestingList', {
extend: 'Ext.List',
xtype: 'testinglistcard',
requires: [
'Ext.field.Select',
'Ext.field.Search',
// 'bluebutton.view.BlueButton.MemberDetail',
'Ext.plugin.ListPaging',
'Ext.plugin.PullRefresh',
'Ext.dataview.Override'
],
config: {
styleHtmlContent: true,
scrollable: 'vertical',
indexBar: true,
singleSelect: true,
onItemDisclosure: true,
grouped: true,
variableHeights : false,
store : { xclass : 'bluebutton.store.BlueButton.Testing'},
itemHeight :100,
loadingText : 'loading',
id :'testinglist',
plugins: [
{ xclass: 'Ext.plugin.PullRefresh',
refreshFn: function() {
var transaction = Ext.ModelMgr.getModel('bluebutton.model.BlueButton.Testing');
var proxy = transaction.getProxy();
proxy.setExtraParam('refresh', 'true' );
Ext.getStore('testingstore').load();
},
},
{
xclass: 'Ext.plugin.ListPaging',
autoPaging: true,
loadNextPage: function() {
var transaction = Ext.ModelMgr.getModel('bluebutton.model.BlueButton.Testing');
var proxy = transaction.getProxy();
proxy.setExtraParam('refresh', );
Ext.getStore('testingstore').load();
}
},
],
masked: {
xtype: 'loadmask',
message: 'loading...'
}, // masked
emptyText: '<p class="no-search-results">No member record found matching that search</p>',
itemTpl: Ext.create(
'Ext.XTemplate',
'<div class="tweet-wrapper">',
'<table>',
'<tr>',
'<td>',
' <div class="tweet">',
' <h3>{invoiceId}</h3>',
' <h3>Name: {billNumber}</h3>',
' <h3>Point Avalaible : {invoiceDate} , Last Visited : {invoiceAmount}</h3>',
' </div>',
'</td>',
'</tr>',
'</table>',
'</div>'
),
},
});
Store.js
Ext.define('bluebutton.store.BlueButton.Testing', {
extend: "Ext.data.Store",
requires: ['bluebutton.model.BlueButton.Testing'],
config: {
grouper: {
groupFn: function (record) {
return record.get('invoiceId')[0];
}
},
model :'bluebutton.model.BlueButton.Testing',
storeId :'testingstore',
autoLoad: true,
pageSize: 5,
clearOnPageLoad: false,
}
});
Model.js
Ext.define('bluebutton.model.BlueButton.Testing', {
extend: 'Ext.data.Model',
config: {
idProperty: 'testingModel',
fields: [
{ name :'invoiceId'},
{ name: 'billNumber' },
{ name: 'invoiceDate' },
{ name: 'invoiceAmount' },
{ name :'downloadLink'},
{ name: 'refresh' },
],
proxy: {
type: 'rest',
url: 'http://192.168.251.108:8080/RESTFulExample/rest/json/metallica/invoicejsonPost',
reader: 'json',
actionMethods: {
create: 'POST',
read: 'GET',
update: 'PUT',
destroy: 'DELETE'
},
noCache: false, // get rid of the '_dc' url parameter
// extraParams: {
// userid: "test",
// // add as many as you need
// },
reader: {
type: 'json',
rootProperty: 'invoice'
},
writer: {
type: 'json',
},
}
}
});
I need to assign extra param "refresh" to true when i refresh the list. On the other hand, if the load more event fire i need to assign param refresh to false. Please give me solution. Thanks
I dont think you can do it the way you ask. But you can listen to the load event and change your refresh parameter there.
{
xtype: 'store',
//Your Code
listeners: {
load: function(store){
store.getProxy.setExtraParam('refresh', false);
}
}
}
Hope it helps

How to filter the Store?

Who knows how to filter the Store right?
I tried to do it in listener of leafItemTap of Nested List, but my leaf items not tapping now. Massage in console: "Uncaught TypeError: Cannot call method 'filter' of undefined "
Here is Nested list, where Store must be filtered:
Ext.define('Application.view.SplitView', {
extend: 'Ext.Container',
xtype: 'splitview',
config: {
layout: 'card',
store: null
},
initialize: function() {
this.nestedList = Ext.create('Ext.NestedList', {
title : 'Рецепты',
detailCard: Ext.create('Application.view.MainDetail'),
store: this.getStore(),
listeners: {
scope: this,
leafitemtap: this.onLeafItemTap
}
});
this.setItems([this.nestedList]);
},
updateStore: function(newStore) {
if (this.nestedList) {
this.nestedList.setStore(newStore);
}
},
onLeafItemTap: function(nestedList, list, index, node, record, e) {
var psn = record.get('text');
console.log(psn);
var detailCard = nestedList.getDetailCard();
var store = Ext.getStore('Application.store.DetailStore');
store.filter('title', 'Brownies');
console.log(store);
}
});
This is my Store, which I want to filter:
Ext.define('Application.store.DetailStore', {
extend: 'Ext.data.Store',
config: {
model: 'Application.model.DetailModel',
autoLoad :true,
sorters: 'title',
grouper : function(record) {
return record.get('title')[0];
},
proxy: {
type: 'ajax',
url : '/data/data1.php',
reader: {
type: 'json',
rootProperty:'recipes'}
}
}
});
And Store's model:
Ext.define('Application.model.DetailModel', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'title', type: 'string'},
{name: 'serves', type: 'string'},
{name: 'cooktime', type: 'string'},
{name: 'ingridients', type: 'string'},
{name: 'picture', type: 'string'},
{name: 'kitchen', type: 'string'},
{name: 'category', type: 'string'},
{name: 'instructions', type: 'string'}
]
},
fullName: function() {
var d = this.data,
names = [
d.title
];
return names.join(" ");
}
});
I'm new in Sencha and every advice will be useful
The following error means the object which you're calling the filter function on is undefined
"Uncaught TypeError: Cannot call method 'filter' of undefined "
In your case, the store is undefined.
Try to get it by doing :
var store = Ext.getStore('DetailStore');
Also, you could check what stores are in the StoreManager by doing :
console.log(Ext.data.StoreManager.all);
Hope this helps

Sencha Touch 2 Store TypeError

I'm following the video on the Sencha website, for creating my first application.
This is the video I'm following: Video
This is the code I'm using for the Blog tab:
Ext.define('GS.view.Blog',{
extend: 'Ext.navigation.View',
xtype: 'blogpanel',
requires: [
'Ext.dataview.List',
'Ext.data.proxy.JsonP'
],
config: {
title: 'Blog',
iconCls: 'star',
items: {
xtype: 'list',
itemTpl: '{title}',
store: {
autoLoad: true,
fields: ['title', 'author', 'content'],
root: {
leaf: false
},
proxy: {
type: 'jsonp',
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog',
reader: {
type: 'json',
rootProperty: 'responseData.feed.entries'
}
}
}
}
}
});
In the Safari Console, it is giving me the following error on StoreManager.js:97:
TypeError: 'undefined' is not a valid argument for 'instanceof' (evaluating 'store instanceof Ext.data.Store')
What am I doing wrong?
add this code at line store:
store: new Ext.create('Ext.data.Store',{
autoLoad: true,
fields: ['title', 'author', 'content'],
root: {
leaf: false
},
proxy: {
type: 'jsonp',
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog',
reader: {
type: 'json',
rootProperty: 'responseData.feed.entries'
}
}
})

Variables between List

My problem is... I have a list who is completed by a store and this store comes from a proxy (json). When i clik in a item of the list i need a detail information, and this detail information comes from anothe json.
For example:
ArtistList and ArtistDetail
When i click in an item of artistList i need a call to
http://localhost/json-detail/45
if i click in another item...
http://localhost/json-detail/50 etc...
My problem is that i can't send the parameter to the other view... or maybe the error is in my concept of lists... :S
This is my list view:
var listaArtistas = {
xtype: 'list',
title: 'Artistas',
height: 240,
store: {
autoLoad: true,
fields: ['node'],
proxy: {
type: 'ajax',
url: 'http://localhost/json-artistas',
reader: {
type: 'json',
rootProperty: 'nodes'
}
}
},
listeners: {
itemtap: function(lista,index,target,record,e,eOpts)
{
var artistDetail = new Ext.create('app.view.ArtistDetail');
artistDetail.setArtistID('45');
panelHomeNav.push(artistDetail);
}
},
itemTpl: tpl
};
This is my detail:
Ext.define('app.view.ArtistDetail',{
extend: 'Ext.Panel',
xtype: 'artistdetail',
style: "background-image:url('/resources/images/fondoartista.png');",
config:{
title: 'Artistas',
iconCls: 'star',
ArtistID: '',
items:
{
title: 'Artistas',
items: [artistDetailPanelContenedor]
}
}});
And need something like this
var listaEspectaculo = {
xtype: 'list',
title: 'Artistas',
store:
{
autoLoad: true,
fields: ['node'],
proxy: {
type: 'ajax',
url: 'http://localhost/json-artistasdetail/'+getArtistID, <<<<<<<<<<------ PROBLEM
reader: {
type: 'json',
rootProperty: 'nodes'
}
}
},
listeners: {
itemtap: function(lista,index,target,record,e,eOpts)
{
var eventDetail = new Ext.create('app.view.EventDetail');
panelHomeNav.push(eventDetail);
}
},
itemTpl: tplEspectaculo
};
THx for help !!!
Maybe this could help:
How to pass value from controller to data store in sencha touch
handler: function () {
Ext.dispatch({
controller: MyApp.controllers.controller,
action: 'myActionOnController',
id: e.get{'id'}
});
}
You can call ext.dispatch from your "itemtap", then in the controller you can call a new view with you parameters, remember use something like this:
myActionOnController: function (options) {
var city = options.id; //if you want to use your parameters
var newView = Ext.create('MyApp.view.viewOfSomething');
this.getMain().push(newView);
},