I am unable to load the below xml in to List using Sencha.
<?xml version="1.0" encoding="UTF-8"?>
<bdayevents>
<bdayevent>Acceptance Letters</bdayevent>
<bdayevent>Acceptance Letters</bdayevent>
</bdayevents>
This is the model which i am trying to use as there are no attributes to my XML.
Ext.regModel('BEvent',{name:'bdayevent'});
var store = new Ext.data.Store({ model: 'BEvent',
proxy: {
type: 'ajax',
url: 'http://localhost:8080/JSON/BirthdayInvitations.xml',
reader: {
type : 'xml',
root : 'bdayevents',
model : 'BEvent',
record : 'bdayevent'
}
}
});
This is the List which i am trying to invoke during ready.
var list = new Ext.List({
fullscreen: true,
onItemDisclosure: {
scope: 'test',
//handler: makeJSONPRequest
},
itemTpl : '{event}',
grouped : true,
indexBar: true,
store: store,
modal:true
});
list.show();
}
});
The result of above snippet is empty page with index dispalying a to z.
Please help me in resolving this issue.
Thanks,
Shyam
try this
Ext.regModel('BEvent', {
fields: ['bdayevent']
});
var store = new Ext.data.Store({
model: 'BEvent',
method:'get',
proxy: {
type: 'ajax',
url : 'BirthdayInvitations.xml',
//url: 'test1.xml',
reader: {
type : 'xml',
record: 'bdayevents'
}
},
autoLoad: true
});
var XMLTpl = new Ext.XTemplate(
'<tpl for=".">',
'<div>{bdayevent}',
'</tpl>'
);
var list = Ext.create('Ext.List', {
fullscreen: true,
store: store,
onItemDisclosure: {},
itemTpl: XMLTpl
});
Related
Morning,
I'm new to Sencha. I have the following code in my login.js, which retrieves form fields from a JSON doc on remove server. It creates an array from the data, which I need tro be able to use to populate the form:
var url = 'http://domainxxx.net/';
loginFields = new Array();
Ext.onReady(function(){var theform = Ext.Ajax.request({
url: url+'login',
type: 'get',
scope: this,
dataType: "JSON",
success: function(response){
formFields = new Array();
var numFields = Ext.JSON.decode(response.responseText).length;
for (var inf=0;inf<numFields;inf++){
afield = new Array();
afield['xtype'] = 'textfield';
afield['name'] = Ext.JSON.decode(response.responseText)[inf].Name;
afield['itemId'] = Ext.JSON.decode(response.responseText)[inf].Name;
afield['required'] = true;
afield['description'] = Ext.JSON.decode(response.responseText)[inf].Description;
afield['placeHolder'] = Ext.JSON.decode(response.responseText)[inf].Description;
afield['maxlength'] = Ext.JSON.decode(response.responseText)[inf].Length;
if(Ext.JSON.decode(response.responseText)[inf].Type == 1){afield['xtype']= 'passwordfield';}
if(Ext.JSON.decode(response.responseText)[inf].Type == 0){afield['xtype']= 'emailfield';}
loginFields.push(afield);
}
console.log(loginFields);
}
})
});
The problem is then using this variable to populate the form. I tried placing it in the form config, as shown below, but no luck. I also tried using localStorage, but that didn't work either.
Ext.define('axis3.view.Login', {
extend: 'Ext.form.Panel',
alias: "widget.loginview",
requires: ['Ext.form.FieldSet', 'Ext.form.Password', 'Ext.Label', 'Ext.Img'], config: {
title: 'Login',
itemId: 'loginform',
items: [
{
xtype: 'image',
src: Ext.Viewport.getOrientation() == 'portrait' ? 'images/logo.png' : 'images/logo.png',
style: Ext.Viewport.getOrientation() == 'portrait' ? 'width:271px;height:93px;margin:2em auto' : 'width:271px;height:93px;margin:2em auto'
},
{
xtype: 'label',
html: 'Login failed. Please enter the correct credentials.',
itemId: 'signInFailedLabel',
hidden: true,
hideAnimation: 'fadeOut',
showAnimation: 'fadeIn',
style: 'color:#990000;margin:5px 0px;'
},
{
xtype: 'fieldset',
title: 'Login',
items: [
FORM VARIABLES IN HERE
]
},
{
xtype: 'button',
itemId: 'logInButton',
ui: 'action',
padding: '10px',
text: 'Log In'
}
],
listeners: [{............
Any advice is most welcome
You are using an Array instead of an Object. Rather than saying var aField = new Array(), say var aField = new Object().
Note that, for short hand, you can also do this instead of using a constructor:
var myArray = [];
car myObject = {};
I am trying to build a dynamic tree. I am getting my data from a C# WCF Service. It is returning me JSON data , but data is not reflecting in tree.
I am using EXTJS 4.
.Js Code -
Ext.require([
'Ext.tree.*',
'Ext.data.*',
'Ext.tip.*'
]);
Ext.onReady(function () {
Ext.QuickTips.init();
var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'Services/InfographicsDataService.svc/GetTree'
},
root: {
text: 'Ext JS',
id: 'src',
expanded: true
},
reader: {
type: 'json',
root: 'd'
}
}); // End of store code
var tree = Ext.create('Ext.tree.Panel', {
store: store,
viewConfig:
{
plugins:{ ptype: 'treeviewdragdrop' }
},
renderTo: 'tree-div',
height: 300,
width: 250,
title: 'Files',
useArrows: true
}); // End of tree
}); // End of ready function
This is the code at my service end-::
[OperationContract]
[WebGet]
public List<TreeNode> GetTree()
{
List<TreeNode> nodes = new List<TreeNode>();
nodes.Add(new TreeNode() { id="src/ModelManager.js", text =
"ModelManager.js" });
nodes.Add(new TreeNode() { id="src/data", text = "data" });
nodes.Add(new TreeNode() { id="src/draw", text = "draw" });
return nodes;
}
Json returned by wcf service--
{"d":[
{
"__type":"TreeNode:#Infographics.Services.Model",
"id":"src\/ModelManager.js",
"leaf":false,
"text":"ModelManager.js"
},
{
"__type":"TreeNode:#Infographics.Services.Model",
"id":"src\/data",
"leaf":false,
"text":"data"
},
{
"__type":"TreeNode:#Infographics.Services.Model",
"id":"src \/draw",
"leaf":false,
"text":"draw"
}]
}
Call is going to server and returning the data but not adding nodes in tree
Page is showing just the root Extjs node.
Initially I thought , it is just root property of reader which I need to set to "d" , but there is something more I am missing.
Can somebody help me in finding what is that small mistake I am making ?
Can you change the store like this and try,
var store = Ext.create('Ext.data.TreeStore',
{
proxy:
{
type: 'ajax',
url: 'Services/InfographicsDataService.svc/GetTree',
reader:
{
type: 'json',
root: 'd'
}
},
root:
{
text: 'Ext JS',
id: 'src',
expanded: true
}
});
I am working in sencha touch 1.1, specifically, using Ext.List. But instead of using a proxy to populate the Ext.List object, I need to load the data right straight from an array javascript variable like
var = [["1","Ángel Quezada"],["2","Christian Herrera"],["3","Francisco Quispe"]]
I don't have any trouble populating the Ext.List in the proxy way, first I declare le model, then the proxy and finally the List. According the next lines.
Ext.regModel('Cronograma', {
idProperty: 'nrocuota',
fields: [{name:'nrocuota', type: 'string'}]
});
Ext.regStore('CronogramaStore', {
model: 'Cronograma',
proxy: {
type :'ajax',
url: '/mSAS/cotizacion.do?method=generarCronograma',
reader: {type:'array'}
}
});
this.grdCronograma = new Ext.List({
id: 'notesList',
store: 'CronogramaStore',
emptyText: 'No existe resultado ',
itemTpl: '{nrocuota}',
listeners: {'render':function(thisComponent){}}
});
But right know I have another need. I need to populate the List from an Array Javascript Variable, not using the proxy, I mean
how can I use the
var varArray = [["1","Ángel Quezada"],["2","Christian Herrera"],["3","Francisco Quispe"]]
to populate the Ext.List, I guess there's a way using the Ext.data.Store and its load method. but I can't find it.
Here is dynamic way of doing it, without using static data.
Ext.regModel('Cronograma', {
idProperty: 'nrocuota',
fields: [{name:'nrocuota', type: 'string'}]
});
Ext.regStore('CronogramaStore', {
model: 'Cronograma'/*,
data : [
{ nrocuota : 'Ángel Quezada' },
{ nrocuota : 'Christian Herrera' },
{ nrocuota : 'Francisco Quispe' }] */ // Does not take array [[],[],[]] that was specified in problem statement
});
this.grdCronograma = new Ext.List({
id: 'notesList',
store: 'CronogramaStore',
emptyText: 'No existe resultado ',
itemTpl: '{nrocuota}',
listeners: {'render':function(thisComponent){}}
});
// Here is the dynamic method.
function addToList(data){
var len = data.length;
for(var i=0;i<len;i++){
var note = Ext.ModelMgr.create({
nrocuota: data[i][1], //grab only name from the array
}, 'Cronograma');
CronogramaStore.add(note);
CronogramaStore.sync();
}
}
//now just call the function
var data = [["1","Ángel Quezada"],["2","Christian Herrera"],["3","Francisco Quispe"]];
addToList(data);
Ext.regModel('Cronograma', {
idProperty: 'nrocuota',
fields: [{name:'nrocuota', type: 'string'}]
});
Ext.regStore('CronogramaStore', {
model: 'Cronograma',
data : [
{ nrocuota : 'Ángel Quezada' },
{ nrocuota : 'Christian Herrera' },
{ nrocuota : 'Francisco Quispe' }
]
});
this.grdCronograma = new Ext.List({
id: 'notesList',
store: 'CronogramaStore',
emptyText: 'No existe resultado ',
itemTpl: '{nrocuota}',
listeners: {'render':function(thisComponent){}}
});
update to use arrays instead of json object:
Ext.regModel('Cronograma', {
idProperty: 'id',
fields: [ 'id', 'nrocuota' ]
});
var data = [["1","Ángel Quezada"],["2","Christian Herrera"],["3","Francisco Quispe"]];
Ext.regStore('CronogramaStore', {
model: 'Cronograma',
data : data
});
this.grdCronograma = new Ext.List({
id: 'notesList',
store: 'CronogramaStore',
emptyText: 'No existe resultado ',
itemTpl: '{nrocuota}',
listeners: {'render':function(thisComponent){}}
});
or already indicated if you don't have data available at time of creation of store then use store.loadData(data); function
i haven't tested this code myself so if it's not working then please tell me
Model:
app.models.Category = Ext.regModel("Category", {
fields: [
{ name: 'CategoryId', type: 'int' },
{ name: 'ImageUrl', type: 'string' },
{ name: 'ImageUrlFile', type: 'string' },
{ name: 'CategoyName', type: 'string' }
]
});
Storage:
app.stores.CategoryStore = new Ext.data.Store({
id: 'CategoryStore',
model: 'Category',
autoLoad: true,
proxy: {
type: 'scripttag',
url: 'http://localhost:1303/admin/categoriesservice/getcategories',
mehod: 'GET', //not needed
callbackKey: 'callback', //not needed
reader: {
type: 'json',
root: 'categories'//not needed with my JSONP
},
afterRequest: function (request, success) {
console.log("afterRequest");
if (success) {
console.log("success");
} else {
console.log("failed");
}
console.log(request);
}
}
});
Controller:
Ext.regController('Home', {
index: function () {
if (!this.indexView) {
this.indexView = this.render({
xtype: 'HomeIndex'
});
this.items = [app.views.HomeIndex];
}
app.viewport.setActiveItem(this.indexView);//this what i've missed
}
});
View
app.views.HomeIndex = Ext.extend(Ext.DataView, {
html: '<div class="gallery-view" style="display: block;width: 300px;border: 1px solid #fff;height: 300px;"></div>',
store: app.stores.CategoryStore, //full namespace needed
itemSelector: 'div.node',
initComponent: function () {
this.tpl = new Ext.XTemplate(
'<div style="padding:10px 5px 5px 5px;">',
'<tpl for=".">',
'<div class="node" style="background:url({ImageUrl});">',
'</div>',
'</tpl>',
'</div>'
);
//appened to successful solution
this.dataView = new Ext.DataView({
store: this.store,
tpl: this.xtpl,
itemSelector: 'div.node'
});
this.items = [this.dataView];
app.views.HomeIndex.superclass.initComponent.apply(this, arguments);
}
});
Ext.reg('HomeIndex', app.views.HomeIndex);
JSONP Result:
GetCategories([{"CategoryId":101,"CategoyName":"אוכל","ImageUrl":"http://www.teleclal.com/YnetApplicationMall/Content/images/categories/rest.png","ImageUrlFile":null,"InsertDate":"\/Date(1314507534000)\/","IsActive":true,"ApplicationId":0,"Applications":null},{"CategoryId":99,"CategoyName":"הצגות ומופעים","ImageUrl":"http://www.teleclal.com/YnetApplicationMall/Content/images/categories/shows.png","ImageUrlFile":null,"InsertDate":"\/Date(1314442037000)\/","IsActive":true,"ApplicationId":100,"Applications":null},{"CategoryId":111,"CategoyName":"בריאות","ImageUrl":"http://www.teleclal.com/YnetApplicationMall/Content/images/categories/spa.png","ImageUrlFile":null,"InsertDate":"\/Date(1314856845000)\/","IsActive":true,"ApplicationId":0,"Applications":null},{"CategoryId":142,"CategoyName":"נופש ותיירות","ImageUrl":"http://www.teleclal.com/YnetApplicationMall/Content/images/categories/vacation.png","ImageUrlFile":null,"InsertDate":"\/Date(1314713031000)\/","IsActive":true,"ApplicationId":0,"Applications":null},{"CategoryId":143,"CategoyName":"ביגוד","ImageUrl":"http://www.teleclal.com/YnetApplicationMall/Content/images/categories/clothes.png","ImageUrlFile":null,"InsertDate":"\/Date(1314713031000)\/","IsActive":true,"ApplicationId":0,"Applications":null},{"CategoryId":144,"CategoyName":"אתרים ואטרקציות","ImageUrl":"http://www.teleclal.com/YnetApplicationMall/Content/images/categories/attraction.png","ImageUrlFile":null,"InsertDate":"\/Date(1314713031000)\/","IsActive":true,"ApplicationId":0,"Applications":null},{"CategoryId":105,"CategoyName":"חשמל","ImageUrl":"http://www.teleclal.com/YnetApplicationMall/Content/images/categories/elctronic.png","ImageUrlFile":null,"InsertDate":"\/Date(1314713031000)\/","IsActive":true,"ApplicationId":0,"Applications":null}]);
The exception:
Uncaught TypeError: Cannot read property 'length' of undefined
Question:
Help how can i parse via storage or any other way the JSONP issue???
You have set this in your reader
reader: {
type: 'json',
root: 'categories'
}
And I can't see categories element in your json data. Check if this is correct or add this to your json in order to be working probably
{"categories":[ ...//old json //..]}
when I tried to define
function GetCategories(data){console.log(data);}
and then invoking the jsonp response (by ctrl+c/ctrl+v into the console), I was successful, meaning the the data is a valid json string.
but when I inspected your code, I haven't seen a mechanisem that defines that function (GetCategories).
I must say that i'm unfamilier with sencha. but I aswsome that problem is that no callback function was ever created.
I see that you define a 'callbackKey: 'callback''
is there somewhere in sencha documentation that allows you to define a 'callbackValue: 'GetCategories'' or such? try and check into that direction.
Try removing "autoLoad: true" from your code. It resolved my issues on the same matter as yours.
I know the typical reason for a DataView to be blank is because the model or JSON is wrong. From what I can tell, mine is right... so I'm not sure why my DataView is blank.
Controller
rpc.controllers.AboutController = new Ext.Panel({
id: 'rpc-controllers-AboutController',
title: 'About',
iconCls: 'info',
layout: 'card',
scroll: 'vertical',
items: [rpc.views.About.index],
dockedItems: [{ xtype: 'toolbar',
title: 'RockPointe Church | Mobile'
}],
listeners: {
activate: function () {
if (rpc.stores.AboutStore.getCount() === 0) {
rpc.stores.AboutStore.load();
}
}
}
});
View
rpc.views.About.index = new Ext.DataView({
id: 'rpc-views-about-index',
itemSelector: 'div.about-index',
tpl: '<tpl for="."><div class="about-index">{html}</div></tpl>',
store: rpc.stores.AboutStore,
fullscreen: true,
scroll: 'vertical'
});
Store
rpc.stores.AboutStore = new Ext.data.Store({
id: 'rpc-stores-aboutstore',
model: 'rpc.models.AboutModel',
autoLoad: true,
proxy: {
type: 'scripttag',
url: WebService('About', 'Index'),
method: 'GET',
reader: {
type: 'json',
root: 'results'
},
afterRequest: function (request, success) {
if (success) {
console.log("success");
} else {
console.log("failed");
}
console.log(request);
}
}
});
rpc.stores.AboutStore.proxy.addListener('exception', function (proxy, response, operation) {
console.log(response.status);
console.log(response.responseText);
});
Model
rpc.models.AboutModel = Ext.regModel('rpc.models.AboutModel', {
fields: ['html']
});
JSON
mycallback({"results":{"html":"... content removed for brevity ..."},"success":true});
Can anyone see what I might be doing wrong here?
There are no console/javascript errors. And the resources are showing that I am in fact pulling down the JSON from the WebService.
If I use console.log(rpc.stores.AboutStore.getCount()); inside my activate listener on the AboutController, the result is always 0, and I'm not entirely sure why
here's the staging app if you'd like to see the request
http://rpcm.infinitas.ws/ (note, this link will expire at some point)
Try returning your json value as an array instead of an object. I think Ext is expecting an array of records instead of just one.
For example
"{results : [{"html": "Your html"}]}"