Sencha Touch 2 store doesn't load within floating panel - sencha-touch-2

I'm trying to load a list within a floating panel. It works with static values but it doesn't load using a json file.
If I tried this and it works:
var panel = Ext.create('Ext.Panel', {
left: 0,
padding: 10,
width: 300,
height: 300,
modal: true,
hideOnMaskTap: true,
layout: 'fit',
items: [
{
xtype: 'list',
scrollable: true,
ui: 'round',
height: '100%',
store: {
fields: ['name'],
data: [
{name: 'Cowper'},
{name: 'Everett'},
{name: 'University'},
{name: 'Forest'}
]
},
itemTpl: '{name}'
}
]
});
But when I try to call a Json file, it doesn't work. This is the panel:
var panel = Ext.create('Ext.Panel', {
left: 0,
padding: 10,
width: 300,
height: 300,
modal: true,
hideOnMaskTap: true,
layout: 'fit',
items: [
{
xtype: 'list',
scrollable: true,
ui: 'round',
height: '100%',
store: 'storeCardStatus',
itemTpl: '{Card_Status}'
}
]
});
This is the store:
Ext.define('MyApp.store.storeCardStatus',{
extend: 'Ext.data.Store',
config: {
model: 'MyApp.model.modelCardStatus',
autoLoad: true,
proxy: {
type: 'ajax',
url : 'card_status.json',
reader: 'json'
}
}
});
This is the model:
Ext.define('MyApp.model.modelCardStatus', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'Card_Status', type: 'string'}
]
}
});
This is the Json file:
[
{"Card_Status": "Completed"},
{"Card_Status": "Issued"},
{"Card_Status": "In Use"}
]

This has nothing to do with local data vs JSON file. You simply aren't setting the predefined store correctly on the list view. You want to add an alias to the store definition, and define the store as an object with type of your store alias (minus the prefix). Here is a fiddle:
https://fiddle.sencha.com/#fiddle/2bh
(Look specifically at Line #3, and #45)
I would recommend always creating stores via alias like this, it easier allows for management and destruction, and each store created will always be a new instance. Creating stores ahead of time (for example, via Ext.create) and then assigning them to components introduces a huge risk of tying the same store to 2+ dataviews inadvertently.

Related

Why is my list not showing in a floating container in ST2

I'm writing some test code and would like to show a list in a floating container. The test code is not working. Can anyone have a look to see if there is anything I am missing:
var p = Ext.create('Ext.form.Panel', {
xtype: 'panel',
scrollable: true,
centered: true,
width: 300,
height: 300,
items: [
{
xtype:"container",
layout: {
type: 'vbox'
},
items: [
{
xtype: "list",
itemTpl: '{title},{author}',
flex: 1,
store: {
autoLoad: true,
fields : ['title', 'author'],
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'
}
}
}
}
]
}
]
});
Ext.Viewport.add(p);
That's simply because you are trying to put a list inside a FormPanel.
Try to use a container instead, and, in addition, if you only need to put a list inside it, don't use a "vbox" layout but a fit one.
var p = Ext.create('Ext.Container', {
centered: true,
width: 300,
height: 300,
layout: 'fit',
items: [
{
xtype: "list",
...

How to get all the xtypes of a certain type

I have a panel which has items as follows:
{
xtype: "panel",
border: 0,
defaultType: "textfield",
bodyStyle: "background: transparent;",
defaults: {
anchor: "100%",
flex: 1
},
margin: "2 4px",
layout: "hbox",
flex: 2,
items: [
{xtype: "searchvaluefield"}, {xtype: "random" }, {xtype: "searchvaluefield"}
],
}
However these items consist of a dynamic number of elements. In particular there can be an arbitrary number of the xtype "searchvaluefield". I wish to get an array of all the elements in this panel which are of xtype "searchvaluefield". Note I have simplified the problem and the actual problem contains multiple panels within panels which is why I was hoping to avoid looping through things.
If it helps here is the defined xtype I am seeking:
Ext.define("app.view.stock.SearchValueField", {
extend: "Ext.form.field.Text",
alias: "widget.searchvaluefield",
name: "search_value_field",
enableKeyEvents: true,
allowBlank: false,
initComponent: function() {
this.callParent(arguments);
}
});
you can do this by using query method for the panel
yourPanel.query('searchvaluefield'); - returns an array of items matching that xtype.

Image field with sencha touch

I am using sencha touch to make a form.fieldset. In my model I have an image field, how can i do to display the current image of my model? My form.fieldset looks like :
/**
* This is used by the NestedList example to allow editing of an item in the Store
*/
Ext.define('ParkingSencha.view.EditorPanel', {
extend: 'Ext.form.Panel',
requires: ['Ext.form.FieldSet'],
id: 'editorPanel',
config: {
modal: true,
hideOnMaskTap: false,
centered: true,
width: 500,
scrollable: false,
items: [{
xtype: 'fieldset',
items: [
{
xtype: 'textfield',
name: 'keyword',
label: 'Mots clés'
},
{
xtype: 'textfield',
name: 'title',
label: 'Titre'
},
{
xtype: 'textfield',
name: 'image',
label: 'image'
}
]
}]
}]
}
});
For using / loading the image in a formfield, you need to use image component, not textfield.
Do it like this,
....
{
xtype: 'image',
src: 'http://www.sencha.com/assets/images/sencha-avatar-64x64.png',
flex: 1
},
....
There is another solution for this take a label and set a image inside html tag ....:)
like this
{
xtype:'label',
html:'<img src="path of image ">'
}
or the boomslang ans is more than correct i will recommend you to use that ..

EXTJS4: how to set value of displayfield dynamically (from server data)

I want to add an account Info section to my app, it would contain name and role of the current user
In my server side i can get those infos, but i dont know how to send them from server to my form and display them in a displayfield
The only way I know of dynamically populating data from sever is in grids using store.
How can i do this please?
my extjs code:
xtype: 'form',
border: false,
frame: true,
height: 100,
width: 400,
layout: 'column',
items: [
{ columnWidth: .5,
border: false,
frame: true,
height: 50,
defaults: { labelStyle: 'font-size:11px' },
items: [{
xtype: 'displayfield',
id: 'Customer',
fieldLabel: 'Customer',
value: '<span style="color:blue;font-size:9px">IBM</span>'
}]
}, {
columnWidth: .5,
border: false,
frame: true,
margin: '0 0 0 8',
height:50,
defaults: { labelStyle: 'font-size:11px' },
items: [
{
xtype: 'displayfield',
id: 'role',
fieldLabel: 'Role',
value: '<span style="color:blue;font-size:9px">Admin</span>'
}
]
Feel free to ask for more details if its not clear enough.
Thank you
Use form.loadRecord(record). Any fields whose name mathches your model fields will be set.
To get the record you can use MyModel.load() see the sencha guides for this http://docs.sencha.com/ext-js/4-0/#!/guide/data .

Not sure why my subclassed control is not showing up

I'm trying to create a detailed line item form in my application. I created a subclass of Ext.Panel with three form controls in it. Then I started adding that control to my viewable Panel. Only one ever shows up. The others are set to a height of 0. Here's the code:
app.views.Forms.materialsLineItem = Ext.extend(Ext.Panel, {
layout: {
type: 'hbox',
pack: 'center'
},
items: [
new Ext.form.Spinner({
width: 150
}),
new Ext.form.Text({
placeHolder: 'Description',
width: 400
}),
new Ext.form.Text({
placeHolder: 'Price',
width: 150
})
]
});
app.views.Forms.Materials = new Ext.Panel({
fullscreen: true,
layout: {
type: 'vbox',
align: 'stretch'
},
items: [
new app.views.Forms.materialsLineItem(),
new app.views.Forms.materialsLineItem(),
new app.views.Forms.materialsLineItem()
]
});
Hmm it works if you declare your form components using object literals like so:
app.views.Forms.materialsLineItem = Ext.extend(Ext.Panel, {
layout: {
type: 'hbox',
pack: 'center'
},
items: [{
xtype: 'spinnerfield',
width: 150
}, {
xtype: 'textfield',
placeHolder: 'Description',
width: 400
}, {
xtype: 'textfield',
placeHolder: 'Price',
width: 150
}]
});
My guess is that your way only created the fields once and sencha doesn't let you add the same component to multiple containers, so the first two panels didn't actually have anything in them.
If you look at the elements in Chrome's JavaScript console you should see the first two panels are just empty divs.