Error while trying to display content from a store - extjs4

I am trying to display console.log(r.get('info')) but, i am getting the output as (an empty string). What might have caused this error ?
var myst = Ext.getStore('MyStore');
var r = myst.getAt(0);
myst.on('load', function() {
r = myst.getAt(0);
console.log(r);
console.log(r.get('info'));
});
UPDATE 1
MODEL
Ext.define('MyApp.model.MyModel', {
extend: 'Ext.data.Model',
fields: [
{
name: 'info'
}
]
});
UPDATE 2
I actually get Object { phantom=true, internalId="ext-record-18", raw={...}, more...} when i print console.log(r)'and inside raw, i see info:"myname".

To display array or objects try console.dir(object).

Related

SAPUI5 column summing

I developed a SAPUI5 table on frontend having 4 columns, now I need to show the total sum of 1 column. If anyone knows the code related to this please help me
Controller code
onInit: function () {
var oTable = this.byId("producttable");
oTable.addStyleClass("myCustomTable");
//column list item creation
var oTemplate = new sap.m.ColumnListItem({
cells: [
new sap.m.Text({
text: "{Plant}"
}),
new sap.m.Text({
text: "{PlantDesc}"
}),
new sap.m.Text({
text: "{parts: [ {path: 'NetAmount'}, {path: 'currency'}],type: 'sap.ui.model.type.Currency',formatOptions: {showMeasure: false, maxFractionDigits: 0,roundingMode: 'away_from_zero'}}"
})
]
});
var sServiceUrl = "/sap/opu/odata/sap/ZSALES_PLANT001_SRV/";
//Adding service to the odata model
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, false);
//Setting model to the table
oTable.setModel(oModel);
oTable.bindAggregation("items", {
path: "/ZSalesheaderSet",
template: oTemplate
});
I am getting the following errors in console
sap-ui-core.js:187 Assertion failed: could not find any translatable
text for key 'Total Sales-Yesterday' in bundle
'./i18n/i18n.properties' Failed to load resource: the server
responded with a status of 503 ()
getSum: function() {
var sum = 0, items = this.getView().byId("tableId").getItems();
for (var i = 0; i < items.length; i++) {
sum = sum + items[i].getBindingContext("urBoundModel").getObject().urColumn
}
return sum;
}
If you have bound the table to a Odata or JSON model. Just Iterate over your items and sum the bound property of the column.

Facing some issue to print the API response values in one sentence

I am trying to assert and print the response, for that need help.
Below is response body:
{
"createdIncidents":[
{
"incidentRef":"I0000000",
"personName":"API API",
"personType":"Patient"
},
{
"incidentRef":"I0000000",
"personName":"Ballarat HelpDesk",
"personType":"Staff"
},
{
"incidentRef":"I0000000",
"personName":"test api",
"personType":"Visitor"
},
{
"incidentRef":"I0000000",
"personName":null,
"personType":"Hazard"
}
]
}
I am trying to print incidentRef and personType together in a string.
For that, I am using this code:
var data = JSON.parse(responseBody);
data.createdIncidents.forEach(function(incident, personT) {
var personType = "personType" + personT.personType;
var incidents = "incidentRef" + incident.incidentRef;
var pt = tests["incidents created for " + personType ] = 'personType';
var inc = tests["incidents number is " + incidents] = 'incidents';
tests["incidents created for" +inc && + pt ];
});
Here it is not reading the second items inside the function.
In a separate function declaration it works fine.
I want to print it as:
"incidentRef": "I0000000 is created for "personType": "Hazard""
This would log each item from the createdIncidents array to the console - Unsure what you're actually trying to assert against though:
_.each(pm.response.json().createdIncidents, (arrItem) => {
console.log(`Incident Ref: ${arrItem.incidentRef} is created for Person Type: ${arrItem.personType}`)
})
Given your response data, this would be the output:
Incident Ref: I0000000 is created for Person Type: Patient
Incident Ref: I0000000 is created for Person Type: Staff
Incident Ref: I0000000 is created for Person Type: Visitor
Incident Ref: I0000000 is created for Person Type: Hazard
This could be wrapped in a pm.test() and the different items can be asserted against using the pm.expect() syntax.
This is very basic and is very hardcoded but it would check the data in your example:
pm.test('Check the response', () => {
_.each(pm.response.json().createdIncidents, (arrItem) => {
pm.expect(arrItem.incidentRef).to.equal("I0000000")
pm.expect(arrItem.personType).to.be.oneOf(['Patient','Staff','Visitor','Hazard'])
console.log(`Incident Ref: ${arrItem.incidentRef} is created for Person Type: ${arrItem.personType}`)
})
})

How do I operate the m.withAttr tutorials code?

A contrived example of bi-directional data binding
var user = {
model: function(name) {
this.name = m.prop(name);
},
controller: function() {
return {user: new user.model("John Doe")};
},
view: function(controller) {
m.render("body", [
m("input", {onchange: m.withAttr("value", controller.user.name), value: controller.user.name()})
]);
}
};
https://lhorie.github.io/mithril/mithril.withAttr.html
I tried the above code does not work nothing.
It was the first to try to append the following.
m.mount(document.body, user);
Uncaught SyntaxError: Unexpected token n
Then I tried to append the following.
var users = m.prop([]);
var error = m.prop("");
m.request({method: "GET", url: "/users/index.php"})
.then(users, error);
▼/users/index.php
<?php
echo '[{name: "John"}, {name: "Mary"}]';
Uncaught SyntaxError: Unexpected token n
How do I operate the m.withAttr tutorials code?
Try returning m('body', [...]) from your controller.
view: function (ctrl) {
return m("body", [
...
]);
}
render should not be used inside of Mithril components (render is only used to mount Mithril components on existing DOM nodes).
The example is difficult to operate because it's contrived, it's not meant to be working out-of-the-box. Here's a slightly modified, working version:
http://jsfiddle.net/ciscoheat/8dwenn02/2/
var user = {
model: function(name) {
this.name = m.prop(name);
},
controller: function() {
return {user: new user.model("John Doe")};
},
view: function(controller) {
return [
m("input", {
oninput: m.withAttr("value", controller.user.name),
value: controller.user.name()
}),
m("h1", controller.user.name())
];
}
};
m.mount(document.body, user);
Changes made:
m.mount injects html inside the element specified as first parameter, so rendering a body element in view will make a body inside a body.
Changed the input field event to oninput for instant feedback, and added a h1 to display the model, so you can see it changing when the input field changes.
Using m.request
Another example how to make an ajax request that displays the retrieved data, as per your modifications:
http://jsfiddle.net/ciscoheat/3senfh9c/
var userList = {
controller: function() {
var users = m.prop([]);
var error = m.prop("");
m.request({
method: "GET",
url: "http://jsonplaceholder.typicode.com/users",
}).then(users, error);
return { users: users, error: error };
},
view: function(controller) {
return [
controller.users().map(function(u) {
return m("div", u.name)
}),
controller.error() ? m(".error", {style: "color:red"}, "Error: " + controller.error()) : null
];
}
};
m.mount(document.body, userList);
The Unexpected token n error can happen if the requested url doesn't return valid JSON, so you need to fix the JSON data in /users/index.php to make it work with your own code. There are no quotes around the name field.

Calculating a Total for a Grid

I have a grid of the which has actual time as one of its columns. How can I add the rows up to get the total actual time similar to the way it is done on the track team status page.
Edit:
I am currently trying to find the sum using this var sum = grid.getStore().sum('Actuals');, however when I run it, I get this error on the console:
Uncaught ReferenceError: grid is not defined
I have also tried using this piece of code that I found online:
var tasks = [];
var users = [];
that = this
if (data.length ===0) {
this._createGrid(); //to refresh grid when no items in iteration
}
Ext.Array.each(this.tasks, function(task) {
var owner = task.get('Owner');
var total;
Ext.Array.each(data, function(actual){
//some tasks have no owner. If this condition is not checked Uncaught TypeError: Cannot read property '_refObjectName' of null
if (owner && actual.get('User')._refObjectName === owner._refObjectName) {
total = actual.get('Actuals');
}
});
var t = {
FormattedID: task.get('FormattedID'),
_ref: task.get("_ref"),
Name: task.get('Name'),
Estimate: task.get('Actuals'),
Owner: (owner && owner._refObjectName) || 'None',
TaskEstimates: total
};
tasks.push(t);
});
},
but when I try to print total or taskestimate or attempt to find a specific part of tasks (tasks[i][j]) I either get no data or an error
See a not-treegrid code in this post for an example of how to create a row in a grid that sums up values in a specific column (e.g. Estimate)
columnCfgs: [
{
xtype: 'templatecolumn',text: 'ID',dataIndex: 'FormattedID',width: 100,
tpl: Ext.create('Rally.ui.renderer.template.FormattedIDTemplate'),
summaryRenderer: function() {
return "Estimate Total";
}
},
{
text: 'Estimate',dataIndex: 'Estimate',
summaryType: 'sum',
}

How to bind local storage data to store sencha touch 2

//In view i have created one list with item tpl. below is the code
{
xtype:'list',
id:'userReviewList',
title:'User Review',
store:'UserReviewStore',
height:300,
itemTpl:'<div >{Comment}</div>' + '<div >{Rating}</div>' + '<div >{ReviewId}</div>'
}
//Below i am creating model for that with hard coded values in data section.
Ext.define('AppName.store.UserReviewStore',{
extend:'Ext.data.Store',
id:'reviewStore',
config:{
fileds:[
{name:'Comment',type:'string'},
{name:'Rating', type:'int'},
{name:'ReviewId',tyep:'int'}
]
},
data: [
{ Comment: 'nice', Rating: 5, ReviewId: 1 },
{ Comment: 'cool', Rating: 4, ReviewId: 2 },
{ Comment: 'awesome', Rating: 3, ReviewId: 3 }
]
})
//I am able to display data in list view but i need to use local storage data to display in list. Bellow is the code where i get local storage data which my colleague storing when app starts so now i have to retrieve data from local storage and need to bind to store
var retrievedObject = localStorage.getItem('testObject');//getting local storage
var jsonObj = Ext.decode(retrievedObject);//decoding
after this decode i will get one list of values like
var list = jsonObj.userReviewList
i need to bind this list to store how to do that . where i should write logic to bind to store
In controller when your list is activated, shown, or initialized. Some code that can help you to understand what i mean:
Ext.define('MyApp.controller.Main', {
extend: 'Ext.app.Controller',
config: {
refs: {
myList: '#userReviewList'
},
control: {
myList: {
activate: 'onMyListActivate'
},
}
},
onMyListActivate: function(me) {
var retrievedObject = localStorage.getItem('testObject');//getting local storage
var jsonObj = Ext.decode(retrievedObject);//decoding
var list = jsonObj.userReviewList
me.getStore().setData(list);
}
});