Is there an after_activated callback or a good way to implement it for the Spine.Controller?
I am using Spine Stack Manager, I found the active class is actually set when active function of the controller is completed/returned. So there's no interface for me to do something after the html content of the controller is set to show.
There's something I need to do like reseting the height of some elements, which require the corresponding elements to be showing.
Is there a way to do that?
I just found a solution, implement active callback in the Stack Manager controller. It is called AFTER the controller is really set active, and I could get the activated controller instance.
Like the following:
class App.Main extends Spine.Stack
#extend(Spine.Events)
className: 'stack'
controllers:
normal: App.NormalMode
cool: App.CoolMode
crazy: App.CrazyMode
default: 'normal'
routes:
'/normal': 'normal'
'/cool': 'cool'
'/crazy': 'crazy'
constructor: () ->
super
#active (params) =>
for controller in #manager.controllers
controller.doSomething()
Related
Struggling with some basic react-native stuff.
I have a master-detail scenario.
I push an edit button on a list-item to get to a detail-view, in that view I add a save-button to a navigation bar. Plain and simple.
Navigation to the detail-screen is done by:
this.props.navigator.push({
component: EditScreen,
passProps: {
id:myID,
},
onPress: this.onSave,
rightText: 'Save'
});
}
When tapping the save-button on the navigationbar, the onSave method of the parent component is called missing some context of the modifications.
How is this done in react-native?
I'm a react-native beginner, just want a clear view on how this stuff happens before moving to some flux-inspired libs ;-)
Update - Bind to this is not the problem
Flow:
I press a row which triggers an onEdit method passing in the ID of
the item i want to edit
onEdit pushes the EditScreen component on the navigator
onEdit adds the rightText and onPress bound to this (onSave is bound in the constructor as stated by some comments/answers)
When navigating to the EditScreen, the entity is fetched by its id
I edit the entity and press 'Save'
When pressing save, I return to the parent view and have no reference to the entity. That's my problem, not the binding of the method.
When using es6 classes, this is not automatically bound to the function, like React.createClass did. You have to manually bind this to the class functions. There are multiple ways of doing this.
You can use es6 fat arrows to bind this:
onPress: () => this.onSave()
You can use Function.prototype.bind():
onPress: this.onSave.bind(this)
You can also bind them on the constructor, so the method is created only once (most performant way, but won't matter very much if you are just building regular UI; if your onSave function is being called 1000 times per frame, then this might be a good idea):
constructor () {
super()
this.onSave = this.onSave.bind(this)
}
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.
How can a parameter from an URL be read within an AngularJS controller?
Let's say I have an URL like http://localhost/var/:value and I want the value to be stored in a variable within the controller for the /var/:value URL.
I have tried using $routeParams.value and $route.current.params.value but $routeParams is undefined at the beginning and $route doesn't work.
The problem is that you probably inject $routeParams or $route in a controller that is run before a route change has occurred, e.g. your main/master/page controller.
If you inject $routeParams in a controller for a specific route (specified by the controller property when you define the route), then it will work, otherwise you're probably better of listening to the various events the route service broadcasts.
Try to change your code to use
$scope.$on('$routeChangeSuccess', function (ev, current, prev) {
// ...
});
Requirements: Ensure 'ngRoute' is in your app module
Route provider set up as: http://localhost/var/:valName
Function set up as:
function functionName($scope, $routeParams){$scope.value = $routeParams.valName;}
HTML view:
{{value['valName']}}
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()).
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