PDA

View Full Version : Where am I going wrong?



ssdesign
8 Jul 2010, 10:35 PM
Hi,
This might be a stupid one, but this is my first try at localstorage.

I tried to put together something by reading the Solitaire game as well as the API.

When I try to run this code, it says:
Uncaught TypeError: Cannot call mothod 'index' of undefined.


Ext.ns('iFonts');

Ext.onReady(function() {
iFonts.Index.index();
});

Ext.regModel('Font', {
fields: [
{name: 'name', type: 'string'},
{name: 'age', type: 'int'},
{name: 'phone', type: 'string'},
{name: 'alive', type: 'boolean', defaultValue: true}
],

changeName: function() {
var oldName = this.get('name'),
newName = oldName + " The Great";

this.set('name', newName);
}
});


iFonts.Index = new Ext.Controller({
localStorageKey: 'iFontId',
index : function() {

// Create Database
this.fontStore = new Ext.data.Store({
proxy: new Ext.data.LocalStorageProxy({
id: 'iFont-Font'
}),
model: 'Font',
autoLoad: false
});

// Read Database
this.fontStore.read({
scope: this,
callback: function(records, operation, successful) {
if (records.length == 0) {
alert ('No Data');
} else {

}
}
});
}
});

tobinharris
9 Jul 2010, 9:36 AM
You could try moving this....


Hi,



Ext.onReady(function() {
iFonts.Index.index();
});


...further down the script?

ssdesign
10 Jul 2010, 7:29 AM
Tried it, didnt work.

Is there any documentation on Ext.ns ?

As far as I know, its a shortcut for Ext.namespace
If that is the case, why would this code give me an error?

Here is the pseudo code

I just defined

Ext.ns('SomeName');

Then I created a class within that name space:

SomeName.Index = new Ext.Controller({
.........
index : function(){
}
});

Then initiatised the function like this:


Ext.setup({
onReady: function() {
SomeName.Index.index();
}
});

Any suggestions?

tubamanu
10 Jul 2010, 12:11 PM
i've already used Ext.ns without any problems in sencha touch.
Here are some code snippets:

heres my main class, where i init the application and set namespace. aktually namespace is cf


Ext.namespace('cf');
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady: function() {
cf.Main.init();

}
});


in the onready code block, cf.Main.init() class is called this class looks like this..




cf.Main = function(){return {

init: function () {
alert("works");
}
};}();

tubamanu
10 Jul 2010, 12:19 PM
now my post is working^^

i used ext.ns several times, it's also working for sencha touch....heres some code how i used it.


my first file, where i define the namespace, here cf


Ext.namespace('cf');
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady: function() {
cf.Main.init();
}
});



then the Main-class



// define class and namespace here
cf.Main = function(){return {

theTabPanel :false,
theFirstPanel :false,

init: function () {
alert("works")
}
};}();

ssdesign
11 Jul 2010, 6:56 PM
Yes, good point.

It works for me now with the following:

iFonts.Index = function(){return{

but this still gives problem:

iFonts.Index = new Ext.Controller({

The former is how it is done in Solitaire example. But I am not sure how the Ext.Controller works.

TommyMaintz
13 Jul 2010, 1:25 PM
Did you include the Controller.js and View.js that is included in the Solitaire app? We are planning on releasing Ext MVC in the near future, but we can't guarantee that they will look and work anything like the ones included in that example. So it might be better to not rely too much on them for now.