I have a file app/assets/javascripts/calendar/weekplans.js.erb, which contains some basic erb:
var init_weekplans = function() {
//..
allDayText: '<%= t('weekplan.all-day') %>'
//..
}
Rails fails on (pre)compiling this asset with undefined method 't'. I'd like to use the t() method from ActionView::Helpers::TranslationHelper in there. How do I include this? Is it wise to include this at all, or should I simply push any such variable from the controller or view into this init_weekplans function, instead?
You can try with
I18n.t instead of t.
Related
I am looking for a way to replace the object under data.
data() {
return {
form:{ .... }
}
}
I have learnt that I cannot directly change data itself so I moved all my variables under form. I want to replace all the data inside the form so that my form values are changed.
I have found a way to update single values like this;
this.$set(this.someObject, 'planes', true) where the solution is here but I want to replace all the form object.
update_form(){
let self = this
$.ajax({
url: '/formdata/',
type: 'GET',
success: function(response){
self.$set(self.form, needToUpdateAll)
}
});
},
I am stuck right where it says needToUpdateAll. From the docs, it says target, key, value.
I am looking for a solution because I do not want to assign all values one by one (well the object has nested and nested objects :()
Any walk-around would be appreciated
This is not complicated. You don't need $set. Is update_form() in methods? If so, just do this.form = response. Top level names in your data are directly available in the rest of your Vue object.
There are a couple of questions about this that works, but don't in my scenario.
I want to invoke a function defined in my superclass view, instead of invoking a function in the itemTpl itself.
I´ve something like this in the itemTpl:
'<span class="x-button-label" style="" id="ext-element-115">{[this.getTranslation("textcodestr", "Text by default")]}</span>',
And then, I've this function in the itemTpl config.
getTranslation: function (textCode, defaultText) {
var store = Ext.getStore('TranslationsStore');
var index = store.findExact('TextCode', textCode)
if (index > -1) {
return store.getAt(index).data.TextTranslated;
}
return defaultText;
}
It works, but I want to move this function to the superclass of the view, and be able to invoke the function within the template, instead of copy and paste in all the application templates.
Of course that use a hyper-long line that do what is in the function is not ideal.
Is there a way to do this ?
Thanks!
Milton
I managed to solve it by using a singleton helper, which I can invoke from the itemTpl.
Ext.define('MyApp.util.Shared', {
singleton : true,
getTranslation: function (textCode, defaultText) {
var store = Ext.getStore('TranslationsStore');
var index = store.findExact('TextCode', textCode)
if (index > -1) {
return store.getAt(index).data.TextTranslated;
}
return defaultText;
}});
Then, in the itemTpl
'<span class="x-button-label" style="" id="ext-element-115">{[MyApp.util.Shared.getTranslation("textcodestr", "Text by default")]}</span>',
HTH!
Milton.
I'm using Sencha Touch 2.3. I'm trying to get a Store instance inside a controller in a similar way thats defined in this article http://www.sencha.com/learn/architecting-your-app-in-ext-js-4-part-3/.
I've defined the 'Location' store in the Controller config. I then try to get the store using 2 methods that both fail. First through Ext.getStore and the second through getLocationStore which should be an autogenerated function. Both fail. The first call returns undefined and the second call throws an exception because the function is not available.
Ext.define('MyApp.controller.Location', {
extend: 'Ext.app.Controller',
config: {
refs: {
locationSearchField: '#locationSearchField'
},
control: {
locationSearchField: {
action: 'onSearchAction'
}
},
stores: [ 'Location' ]
},
onSearchAction: function() {
var locationSearchStore = Ext.getStore('Location');
if (locationSearchStore == undefined) {
Ext.Logger.warn('Could not locate locationSearchStore');
locationSearchStore = this.getLocationStore();
if (locationSearchStore == undefined)
Ext.Logger.warn('Could not location locationSearchStore again!');
else
Ext.Logger.info('Success!');
}
else
Ext.Logger.info('Success!');
}
});
You can get your store by: Ext.data.StoreManager.lookup('Location') (if it's called MyApp.store.Location).
To be sure, that you are in the right context in the onSearchAction, try to call console.dir(this); and check that this is the controller object itself
First of all, you want to access store in sencha touch but you have given link of extjs. Second, you need to define your store first and then add it in app.js file. And then you can access your store by Ext.getStore('Location') method. For reference you shold learn this http://miamicoder.com/2012/sencha-touch-2-stores-adding-removing-and-finding-records/
I use dgrid to make a simple grid (http://dojofoundation.org/packages/dgrid/tutorials/defining_grid_structures/).
My question is simple : how to put html tag in label columnheader's ? Because if I put an img tag for example, label contains the string img src=...
Thanks
The column definition can provide a function that builds the column header.
var column = {
//...
renderHeaderCell: function(node) {
domConstruct.create('img', {src: ''}, node);
return node;
}
};
See the documentation of the renderHeaderCell() function in the DGrid wiki:
renderHeaderCell(node)
An optional function that will be called to render the column's header
cell. Like renderCell, this may either operate on the node directly,
or return a node to be placed within it.
One-line answer using put-selector:
renderHeaderCell: function(node) {
return put("img[src=/your/image]");
}
Note this function won't work if your column happens to be a selector - because selector.js defines his own renderHeaderCell(node) function.
#craig Thanks for the answer, in my case I only needed to know how to add HTML into the header cell and the renderHeaderCell(node) was definitely the answer.
For anyone else simply needing to add a <br>, <span>, <div> etc to the header cell, here's a couple of simple examples to compare:
Example without using renderHeaderCell(node):
{
label: 'Title',
field: appConfig.fields[0],
sortable: false
}
Example using renderHeaderCell(node):
{
renderHeaderCell: function(node) {
node.innerHTML = '<span class="headerCell">Title<br><br></span>'
},
field: appConfig.fields[0],
sortable: false
}
Then you can target with CSS as normal:
.headerCell {
font-size: 9px;
}
class IndexController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
$custom = "Custom variable";
var_dump($custom);
}
}
How to display the result not using the variables in the template?
P.S. The result of the Echo function is also suppressed. I understand that this is the wrong approach, but it is a quick way to debug the variables.
if you don't see output from controller check if in your template file you have this line:
{{ content() }}
you can use php's var_dump in any place of your code:
var_dump($var);exit;
exit; is to stop anything what happens after this line.
You can also dump your vars in volt's template with volt's function:
{{dump(var)}}
dump() is same as var_dump()
Here are some more useful volt functions:
http://docs.phalconphp.com/en/latest/reference/volt.html#functions
There is an implicit rendering level in the controller, in the first view that is rendered, you must call the getContent() method:
<div class="controller-output"><?php echo $this->getContent(); ?></div>
Or in Volt:
{{ content() }}
Ok, thx twistedxtra for the tip!
In my case, I use Twig.
To resolve my issue I've added a feature to Twig:
$function = new \Twig_SimpleFunction('content', function() use($view) {
return $view->getContent();
});
$this->_twig->addFunction($function);
Now it can be used in templates:
{{ content()|raw }}
Based on your above code , i understand that your required to execute the $custom value.
There are 2 ways as follow
1 - You can write var_dump($custom); and after that put die(); so that after it no code can be executed.
You can write echo $custom , for execute the value of $custom. But you have to stop script execution after it.
May be some times it happen that code as been written but due to template or view file execution it will overwrite your code. You must check the source code does anything printed above tag that you have written in controller.
May this will help you........:)
I know I'm a little late, but, just call
exit;
after your var_dump()
You can totally disable view in the action:
class IndexController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
$custom = "Custom variable";
$this->view->disable();
var_dump($custom);
}
}
Or even use own debug method:
class IndexController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
$custom = "Custom variable";
$this->debug($custom);
}
public function debug($data)
{
$this->view->disable();
var_dump($data);
}
}
Phalcon\Mvc\View\Engine\Twig() change to:
https://gist.github.com/4690638
and use:
{{condent()|raw}}
{{linkTo('#', 'title')|raw}}
This is my fork ;-)
An even simpler approach would be to set "$this->view->disable()" just above your var_dump expression when using volt. Maybe this would also work with other template engines.
Why not use good old
echo "<pre>" . print_r($custom,TRUE) . "</pre>";
Prints nice and ordered array. Have to add it works from both Controllers and Views. In case of Controller, output is placed on top of Controller's view.