Passing variables to setActiveItem - sencha-touch

How do i pass variables with Sencha Touch 2's setactiveitem function.
What I had was (which were working) instead of using setactiveitem i was using pop and push
var main = this.getMain();
main.pop();
main.push({
xtype: 'carddetails',
card: card,
title: card.get('name'),
});
But I switched to panel with layout card and as I activate the view I want to pass some variables:
main.setActiveItem('#carddetails',card); //something like this
How can i pass variables in this case?
Thanks!

You can't, just create a function like updateViewWithData(data) where you update your view before showing it.
By the way, you weren't passing data to your push() function before, you were creating a view by passing a config object (which you don't do anymore with your setActiveItem()).

Related

Weird Vuejs props behavior with arrays

I created a form component where i pass an object prop to it containing strings and an object array. I then i transfer the elements of the props to the component variables so i can edit them without interacting with the props directly like so:
beforeMount(){
this.var1 = this.props.var1
this.var2 = this.props.var2
this.array = this.props.array
}
when i edit all the other variables, close my component and open it again everything resets BESIDES the array. every time i try to interact with it the reset never happens. i know i am not interreacting directly with the props either in any part of my code so i don't really why this happens when when everything works fine. To fix that i had to do the following:
beforeMount(){
this.var1 = this.props.var1
this.var2 = this.props.var2
this.props.array.forEach(element => {
this.array.push(element)
})
}
why does this work exactly?
I have also been having similar problems with method specific variables not resetting after the function is already over so i find these behaviors a little weird. I am also using "v-if" and also tried to use component keys to reset the component but it doesn't work for the array for whatever reason.
try to copy your array like that :
this.array = [...this.props.array]
I'm not sure about it, but as you pass it within an object, you might actually use you array as reference and not values as you 'd like to.

Vuejs not working with dynamic array, works perfectly with static array

When I have
data: {
pictures: [
'http://lorempixel.com/1920/1920?0',
'http://lorempixel.com/1920/1920?1',
'http://lorempixel.com/1920/1920?2',
'http://lorempixel.com/1920/1920?3',
'http://lorempixel.com/1920/1920?4',
'http://lorempixel.com/1920/1920?5',
'http://lorempixel.com/1920/1920?6',
'http://lorempixel.com/1920/1920?7',
'http://lorempixel.com/1920/1920?8',
'http://lorempixel.com/1920/1920?9',
]
}
it renders perfectly, but when I fetch the data and get it like this in the console and perfect data in the vue dev tools
["https://picsum.photos/id/1020/4288/2848",
"https://picsum.photos/id/1021/2048/1206",
"https://picsum.photos/id/1022/6000/3376",
"https://picsum.photos/id/1023/3955/2094",
"https://picsum.photos/id/1024/1920/1280",
__ob__: Observer]
it populates the dom but not rendered.
what am I missing??
If I face that situation then I check if I have created that property as reactive.
Means I have added v-model on it or not.
Other way is to add it in watch propery as shown below
watch:{
//just write name of the data propery and make it function
picutres(){}
//that's it
}
Now it will listen for the changes.
If you still somehow cannot fix that problem then other solution it to use custom events or a function
You will call function or trigger an event whenever you change your pictures array.
Then in function or event you can update your pictures array

Calling a function or targeting an element in another controller in Titanium Alloy

So, I'm creating a custom modal window:
var modal = Alloy.createController('modal');
modal.getView().open();
Inside the Modal controller is a function called changeTitle and in the view is a label with the id modalTitle. What I'm trying to figure out is how to call either one from the controller that launched the Modal window.
I thought the following would call the function in the controller, but no dice:
modal.changeTitle('foo');
Similarly I thought the following would target the label in the newly created view, but again, no dice.
var modalWin = modal.getView();
modalWin.$.modalTitle = 'foo';
You have to expose the function changeTitle to the world, using exports. So inside the modal controller you have created, it would look like this:
exports.changeTitle = function() {
// Your function definition...
};
For the second part, once again, that is not globally available, I suppose you could do this inside your modal controller:
exports.$ = $;
Then what you wrote will work, but that seems very dangerous to expose the inner members to the outside world. I would nest only the functionality you need in a exposed function like above.

Sencha Touch - this.getParent() returns Cannot call method 'getParent' of undefined

I'm trying to get parent component in View but always get this error:
Cannot call method 'getParent' of undefined
Here is the code:
initialize: function() {
this.callParent();
this.loadMates();
},
loadMates: function() {
var store = Ext.create('App.store.user.Mates');
store.getProxy().setExtraParam('userId', this.getParent().getUserId());
this.setStore(store);
}
I've no idea why the initialized View is undefined. I've tried to push "this" as parameter without any success.
Thanks a lot in advance.
EDIT:
I've found sth here:
http://www.sencha.com/forum/showthread.php?174406-this.parent-and-this.getParent()-always-return-undefined-in-initialize
Well, I've moved all of the logic into Controller. In refs there is link to parent and actual view. Now I can access parent's attributes easily. Loading function is called right after the actual view has been pushed.

Sencha touch suitable document.ready type function

In Jquery theres a function
$(document).ready(function (){..}
Is there such a thing in Sencha Touch 2?
I'm aware of
Ext.Setup({ onReady: function () {...} })
However I can only call Ext.Setup once. If I have multiple views how would I take care of this? I would like a function to load when a view is loaded. Do I have to this via a controller? Can I use a snippet of code injected into the index.html (The platform is built on node and requires this)?
Inside of your controller that requires the view just add an init: function() { //do something }, extjs will take care of the rest... usually if your trying to call a function that requires the view to be loaded, then add the 'painted' listener to your view and it will be called when the view is rendered