how to get id value of the item (within item)? - extjs3

I need to get value for id, do this:
Application.Exaple = Ext.extend(Ext.form.FormPanel, {
record_id : 0,
initComponent : function() {
Ext.apply(this, {
items: [
{
name : 'id',
id : 'id',
fieldLabel : 'ID',
readOnly : true,
hidden : true,
listeners : {
'render' : function() {
this.record_id = this.value;
}
}
},
{
name : 'pum',
id : 'pum',
handler : function() {
alert(this.record_id); // not work
}
but does not work. What am I doing wrong?

This looks like scope error.
you are trying to refer to the record while your current 'this' is the button.
You can do one of 2 things:
1) pass a scope to the handler like this:
{
name : 'pum',
id : 'pum',
scope: YOUR OBJECT HERE,
handler : function() {
alert(this.record_id); // not work
}
2) register the click event of the button from outside like this:
after you call the base form super class on your init method...
{
...
this.numBtn = this.items.itemAt(1);
this.numBtn.on('click',function(){YOUR LOGIC HERE},YOUR SCOPE HERE);
}
Hope this helps...

Related

how to add new field with many data in that field in MongoCosmosDB

I would like to add new field into json already have in mongoDB Cosmos like this
{
"_id" : "6396cde306fd2d1088d584e4",
"userName" : "user-20526"
}
Now I would like to add a others field like this bellow userName field:
{
"_id" : "6396cde306fd2d1088d584e4",
"userName" : "user-20526",
"others": [
{
"address" : "city",
"phone" : "12345676543"
}
]
}
I user this function to do that thing, with updateDocument but it's not works for me:
const updateDocuments = async (value, condition, collectionName) => {
const DATABASE_COLLECTION_NAME = collectionName;
if (!db)
throw Error('findDocuments::missing required params');
const collection = await db.collection(DATABASE_COLLECTION_NAME);
const filter = { condition };
const filterJSON = JSON.parse("{" + filter.condition + "}");
const options = { upsert: true };
// get value (condition) and convert it to correct JSON format before call it in update variable
const getValue = { value }
const valueJSON = JSON.parse("{" + getValue.value + "}");
const updateDoc = {
$set: valueJSON
};
return await collection.updateOne(filterJSON, updateDoc, options);
}
The above function only works when we update one field that already have in data, the example I would like to update userName data, then that function is work, If I use that function to add new one then it's not, not add new one, how can I create more to add new field as what I expected before
anyone please help me

ValidationError: user: Cast to Embedded failed for value "[]"

I am trying to insert a new message into the database using expressjs and mongoose.
But I'm getting a ValidationError in the process. The following is printed at the console.
error while storing message ::: ValidationError: user: Cast to
Embedded failed for value "[]" at path "user"
The code is as follows:
socketAPI.io.on('connection', function(socket){
socket.on('chat-sent', function(param) {
ChatUser.find({username : param.username}).then(async (usr)=>{
if(usr){
try{
var mess = new GroupMessage();
mess.group = (await Group.findOne({name : groupName}));
mess.message = param.message;
mess.user = usr;
mess.save((err)=>{
if(err){
console.log('error while storing message ::: '+err);
}
else{
console.log('message succesfully stored');
}
});
}catch(err){
console.log('error collecting group ::: '+err);
}
}
});
socket.emit('group-message-handled', { user : param.username, message : param.message});
});
});
The insertion code makes use of the following models:
var userSchema = new mgoose.Schema({
username : {
type : String,
required : true,
unique : true,
maxlength : [15, 'Too long username. Max 15 allowed']
},
name : String
});
var groupSchema = new mgoose.Schema({
name : {
type : String,
required : true,
unique : true
},
categories : [String]
});
var groupMessageSchema = new mgoose.Schema({
user : userSchema,
group : groupSchema,
message : {
type : String,
required : true,
minlength : 1
}
});
var ChatUser = mgoose.model('ChatUser', userSchema);
var Group = mgoose.model('Group', groupSchema);
var GroupMessage = mgoose.model('GroupMessage', groupMessageSchema);
What causes this error and how can I fix it?

Uncaught TypeError when loading store in button handler function

I got Uncaught TypeError when loading store in button handler function,
is there something wrong with my
Code:
{
xtype: 'button',
text: 'Click me',
handler: function() {
var store = Ext.create('Ext.data.Store', {
autoLoad : true,
proxy: {
type: 'ajax',
url : 'MyUrl'
}
});
}
}
Error Message:
Uncaught TypeError: instance[configPropMap[name].names.get] is not a function
Debugger screenshots:
name is async
but instance has no getAsync function
I've got a solution, use syncajax below instead of proxy.ajax.
Ext.define('MyApp.store.proxy.SyncAjax', {
extend : 'Ext.data.proxy.Ajax',
alias : 'proxy.syncajax',
config : {
async : false
},
buildRequest : function() {
var me = this,
request = me.callParent(arguments);
request.defaultConfig.async = me.getAsync();
request.getAsync = function() {
request.getAsync = null;
return me.getAsync();
};
return request;
}});

Mootools class: call a class method from an event handler

is it possible to call a class method from within an event handler?
I mean, something like this:
initialize: function(options) {
/* initial options */
this.setOptions(options);
this.area = (this.options.status == 'out') ? $(this.options.loggedoutArea) : $(this.options.loggedinArea);
this.button = $(this.options.buttonArea);
this.button.addEvent('click', function(){
this.showHideBanner();
});
},
showHideBanner: function() {
this.area.setStyle('display', 'none');
},
see full example here http://jsfiddle.net/dvzj6/
I managed to find a solution using this code:
initialize: function(options) {
/* initial options */
this.setOptions(options);
this.area = (this.options.status == 'out') ? $(this.options.loggedoutArea) : $(this.options.loggedinArea);
this.button = $(this.options.buttonArea);
this.button.addEvent('click', function(){
this.showHideBanner();
}.bind(this));
},
see also: http://jsfiddle.net/uA3Ak/

Mongoose Static Not Returning Object After Query

I want to make a method in my model to return the mongodb id of a user given his twitterid. It looks something like this:
userSchema.statics = {
getMongoIdByTwitterName : function (twittername){
this.findOne(({twitterID : req.user.id},
function(err, user){
};
)
}
}
But this obviously doesnt return anything, how do I make this function return the user?
What about using a callback function?
userSchema.statics = {
getMongoIdByTwitterName : function (twittername, callback){
this.findOne(findOne({twitterID : req.user.id},
callback(err, user);
)
}
}