If I call Ember.inspect(component), I get a response like:
<app#component:my-component::ember1246>
This suggests that the component is aware of its own name (my-component). Is there a way to access just that name?
Ember.inspect() calls the objects toString() which in turn calls some internal ember metal functions to derive the name.
There is however an internal property which people have been using to get the name:
this.__proto__._debugContainerKey
This outputs component:my-component, then you can just split on :. There's an issue which will create a public way of exposing object meta information which we'll be able to use in the future: https://github.com/emberjs/ember.js/issues/10742
This regex will do the trick:
//Returns a string with full name of component, like: <ProjectName#component:path/to/component-name::ember793>
let componentName = this.toString ();
//This regex will match the component and capture the latest part of component path.
let regex = componentName.match (/<[a-zA-Z]+#[a-zA-Z]+:(?:[a-z]+[\/])*([-a-z]+)::[a-zA-Z]+[0-9]+>/);
//The latest element of array is the component name.
console.log (regex[regex.length-1]); //component-name
See https://regex101.com/r/rX9bQ7/3 for full explanation about how this works.
Related
Is it possible to find all Ember components based on their name using a wildcard or regex?
so far I found a way to find a component by its fullName:
appInstance.lookup('component:my-component')
but what I want to achieve is to do something like:
appInstance.lookup('component:my-*')
which will return an array of components whose name begins with 'my-'
You can list the names of all entries by using require.entries:
function getKeys(){
return Object.keys(require.entries).filter(function(key){
return /.*components\/my-.*/.test(key);
};
Then you can make a lookup with this keys. (Be aware that function getKeys returns both component's js file names and template file names.)
The title of the questions pretty much describes what I need to do. It is basically the same as this question, which never received an answer:
Rails 4: get list of permitted attributes (strong parameters) from a controller
Similar to the example provided in that question, it would be the equivalent to something like this, if it existed:
account_update_permitted_params = AccountController.permitted_params(:update)
You basically can't do that due to the nature of strong parameters.
What you define in some_resource_attributes is meant to filter parameters hash of the request. If you look at the method definition, you will see params.require(:some_resource).permit.. - it operates on the params object, which is only present during a request.
So having such method seems to be of very little use.
If you really want to programatically access your whitelisted attributes in the some_resource_attributes, you can go with:
class ResourceController < ApplicationController
LIST = %i(foo bar baz)
private
def resource_attributes
params.require(:resource).permit(*LIST)
end
end
ResourceController::LIST
#=> [:foo, :bar, :baz]
But I dot see a point in this since you can just open controller's code and check it.
I would like to prevent normalizing (dasherized by convention) of the model name and instead use the original name. I want to override the function 'normalizeModelName' as the page http://emberjs.com/api/data/#method_normalizeModelName suggests that this should be possible. But i'm not able to do so.
Simply assigning a new function to DS.normalizeModelName is returning an error: Cannot assign to read only property 'normalizeModelName' of object '[object Object]'.
How could I prevent normalizing of the (internal) model name?
small warning: this is related to 2.10.0
i will not guarantee compatibility beyond or below this version. you need to dig through the corresponding files yourself.
since i had a similar problem i dug through the sourcecode of some ember-data stuff and came to the following conclusion:
you need to extend DS.JSONAPIAdapter with pathForType(name) wich essentially takes the name and camelizes as well as pluralizes it before it's being returned as plain text string.
this usually converts model names from foo-bar to fooBars by doing this: https://github.com/emberjs/data/blob/v2.10.0/addon/adapters/json-api.js#L134-L137
now about the opposite:
you need to extend DS.JSONAPISerializer with keyForRelationship(key, typeClass, method)
where key is essentially the model name aquired from relationships in your models. like: fooBar
this usually translates to foo-bar by simply doing return dasherize(key); https://github.com/emberjs/data/blob/v2.10.0/addon/serializers/json-api.js#L453-L455
you might to also dig through some other methods inside the serializer: modelNameFromPayloadKey modelNameFromPayloadType payloadKeyFromModelName payloadTypeFromModelName
just throw in some debugger; lines to see whats going through.
i try to make a String list in Grails.
My part therefore are:
class Name{
static hasMany = [names: String] }
I created also a Controller for the Class and added there:
static scaffold = Name
So far it is working but on in the view there are only the name of the String but i can not add any inputs to the list.
So therefore I'm looking for a solution, hope someone can help.
Thanks in advance!
You question is not very clear because of that what you want.
If i have understood you question here are my answers to you :
1.If you use scaffolding true grails will automatically generate pages and codes based on your domain configuration, if you need more inputs as you said add more domain variables like.i.e
class Name{
static hasMany = [names: String]
//to see more inputs add them here
String description
}
You have only one domain called Name and then what did you expect to see other more inputs you need other more member variables or property's..
If you are not satisfied with the component that grails created fro you can change it on .gsp file.
Great resource here http://goo.gl/f7XV8I
Let me know of further assistance...
I am using icanhaz inside my project. As per documentation it says that it includes the Mustache.js as well.
Now I want to access the embedded Mustache object's to_html() method as follows.
var message = Mustache.to_html(template, json, true);
I am however getting error 'Mustache not defined'. Since Mustache is already included inside iCanHaz.js and I am successfully using ICanHaz's other methods as well, I should not need to include entire Mustache library again just for calling this single method, Or should I?
I just want my template to render as normal string with values replaced from my json object. Any other simple and lightweight way is also appreciated.
Thanks
No need to directly use the Mustache object.
Pass true to your normal ICanHaz render method to get the HTML string:
var message = ich.myTemplate(json, true);