I am using Ember.js for my project, and there is a point when I have to remove all the contents or set every property to ""
or null
for an Ember.Object
.
So what is happening is, within the template, there are handlebars tags that link to some of the objects properties ({{myProperty}}
),so when the object is emptied or every property set to ""
or null
, this binding should still exist if the properties are updated to new values.
Is there a way to achieve this? Is there a way to maybe loop through all the properties quickly?
I am using Ember.js for my project, and there is a point when I have to remove all the contents or set every property to ""
or null
for an Ember.Object
.
So what is happening is, within the template, there are handlebars tags that link to some of the objects properties ({{myProperty}}
),so when the object is emptied or every property set to ""
or null
, this binding should still exist if the properties are updated to new values.
Is there a way to achieve this? Is there a way to maybe loop through all the properties quickly?
Share Improve this question edited Jan 8, 2013 at 13:35 CraigTeegarden 8,2618 gold badges39 silver badges43 bronze badges asked Jan 7, 2013 at 17:33 justkashjustkash 7092 gold badges13 silver badges30 bronze badges2 Answers
Reset to default 4(started writing this thinking that eachAttribute
is a method on Ember.Object
, but it's on DS.Model
instead. So...)
If your object happens to be an Ember Data DS.Model
instance, there is the eachAttribute
method, which takes a callback function. So one way to do what you're suggesting might be:
modelobj.eachAttribute(function(propName){
modelobj.set(propName, null);
});
The only other idea that springs to mind is instantiating a new "blank" instance of your object, and assigning it in the old one's place...I think handlebars bindings would update properly in most cases if you did that.
Would it work for your application to use an {{#if}}
statement in the template to conditionally show/hide your properties?
Like this:
{{#if view.showStuff }}
<p>{{view.myProperty1}}</p>
<p>{{view.myProperty2}}</p>
<p>{{view.myProperty3}}</p>
{{else}}
<p>Not showing content</p>
{{/if}}
If showStuff
is true then your properties will be rendered, otherwise it will display the other html.
Example http://jsfiddle/cteegarden/rHafx/1/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745179861a4615369.html
评论列表(0条)