Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8472445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:04:36+00:00 2026-06-10T17:04:36+00:00

I have an array object in View with binding from Controller. When I change

  • 0

I have an array object in View with binding from Controller. When I change the array in controller, the array in view change properly. But my template for view that seems to be broken: http://jsfiddle.net/secretlm/2C4c4/84/

When I try to use rerender method in view. My template isn’t broken. This fiddle works well: http://jsfiddle.net/secretlm/2C4c4/85/

HTML:

    <script type="text/x-handlebars" data-template-name="test">
        <button {{action "changeContent" target="App.latController"}}> Change</button>
    {{#each element in view.content}}
 <!-- if openTag is true, <ol> tag is created -->       
       {{#if element.openTag}}
          <ol>                                    
        {{/if}}
             <li>{{element.teo.item.Name}}</li>
 <!-- if closeTag is true, </ol> tag is created -->
        {{#if element.closeTag}}
          </ol>                   
        {{/if}}
    {{/each}}
   </script>​

Javascript:

App = Ember.Application.create({});

App.LatView = Ember.View.extend({
    templateName: "test",
    contentBinding: "App.latController.contentWithIndices",
    onRerender: function() {
        this.rerender();
        console.log(this.get('content'));
    }.observes('content')

});

App.latController = Ember.Object.create({
    changeContent: function() {
        this.set('model', []);
        var model = this.get('model');

        var obj1 = {
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test1",
                "Name": "The name1"
            }
        };
        var obj2 = {
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test2",
                "Name": "The name2"
            }
        }
        var obj3 = {
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test3",
                "Name": "The name3"
            }
        }
        var obj4 = {
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test4",
                "Name": "The name4"
            }
        }
        var obj5 = {
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test5",
                "Name": "The name5"
            }
        }
        model.pushObject(obj1);
        model.pushObject(obj2);
        model.pushObject(obj3);
        model.pushObject(obj4);
        model.pushObject(obj5);

    },



    model: [
        {
           item: {
            "DisplayOrder": 1,
            "Public": true,
            "Description": "The test1",
            "Name": "The name1"
          }
       }
        ,
    {
        item: {
            "DisplayOrder": 1,
            "Public": true,
            "Description": "The test2",
            "Name": "The name2"
        }
    }
        ,
    {
        item: {
            "DisplayOrder": 1,
            "Public": true,
            "Description": "The test3",
            "Name": "The name3"
        }
    },
    {

        item: {
            "DisplayOrder": 1,
            "Public": true,
            "Description": "The test4",
            "Name": "The name4"
        }
    },
    {

        item: {
            "DisplayOrder": 1,
            "Public": true,
            "Description": "The test5",
            "Name": "The name5"
        }
    } ],

            contentWithIndices: function() {
                var length = this.get('model').length;
                return this.get('model').map(function(i, idx) {
                    return {
                        teo: i,
                        openTag: (idx % 4 == 0),
                        closeTag: ((idx % 4 == 3) || (idx == length - 1))
                    };
                });
            }.property('model.@each')

        });

        var view = App.LatView.create({});
        view.append();

When should we use rerender method manually? Is there any way to do that without re-rendering my view? Any idea is welcomed, thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:04:37+00:00Added an answer on June 10, 2026 at 5:04 pm

    I have tried to rewrite your example by using another strategy http://jsfiddle.net/davidsevcik/FjB3E/

    Instead of counting the indices I used the Array.slice function to create groups of four items. It also makes the code clearer.

    <script type="text/x-handlebars" data-template-name="test">
    <button {{action "changeContent" target="App.latController"}}> Change</button>
    {{#each elementGroup in view.content}}
        <ol>    
            {{#each element in elementGroup}}                
                 <li>{{element.item.Name}}</li>
            {{/each}}
        </ol>                   
    {{/each}}
    </script>​
    

    Javascript:

    App = Ember.Application.create({});
    
    App.LatView = Ember.View.extend({
        templateName: "test",
        contentBinding: "App.latController.contentSlicedBy4"
    });
    
    App.latController = Ember.Object.create({
        changeContent: function() {
            this.set('model', []);
            var model = this.get('model');
    
            var obj1 = {
                item: {
                    "DisplayOrder": 1,
                    "Public": true,
                    "Description": "The test1",
                    "Name": "The name1"
                }
            };
            var obj2 = {
                item: {
                    "DisplayOrder": 1,
                    "Public": true,
                    "Description": "The test2",
                    "Name": "The name2"
                }
            }
            var obj3 = {
                item: {
                    "DisplayOrder": 1,
                    "Public": true,
                    "Description": "The test3",
                    "Name": "The name3"
                }
            }
            var obj4 = {
                item: {
                    "DisplayOrder": 1,
                    "Public": true,
                    "Description": "The test4",
                    "Name": "The name4"
                }
            }
            var obj5 = {
                item: {
                    "DisplayOrder": 1,
                    "Public": true,
                    "Description": "The test5",
                    "Name": "The name5"
                }
            }
            model.pushObject(obj1);
            model.pushObject(obj2);
            model.pushObject(obj3);
            model.pushObject(obj4);
            model.pushObject(obj5);
    
        },
    
    
    
        model: [
            {
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test1",
                "Name": "The name1"
            }}
            ,
        {
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test2",
                "Name": "The name2"
            }}
            ,
        {
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test3",
                "Name": "The name3"
            }},
        {
    
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test4",
                "Name": "The name4"
            }},
        {
    
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test5",
                "Name": "The name5"
            }},
        {
    
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test6",
                "Name": "The name6"
            }},
        {
    
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test7",
                "Name": "The name7"
            }},
        {
    
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test8",
                "Name": "The name8"
            }},
        {
    
            item: {
                "DisplayOrder": 1,
                "Public": true,
                "Description": "The test9",
                "Name": "The name9"
            }}],
    
        contentSlicedBy4: function() {
            var result = [],
                begin = 0,
                model = this.get('model'),
                slice = model.slice(begin, begin + 4);
    
            while (!Em.empty(slice)) {
                result.push(slice);
                begin += 4;
                slice = model.slice(begin, begin + 4);
            }
            return result;
        }.property('model.@each', 'model')
    
    });
    
    var view = App.LatView.create({});
    view.append();​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to receive json object from view to controller using $.ajax method but
So I have a search controller that returns a array of Object IDs (in
I have an array that looks like this: [ Object actions: Array[2] comments: Object
I have an array that is passed through the ViewData to my view. This
In a view, I get an array of objects. I want to have a
I have an array of Ember.Object s which is displayed by Handlebars {{#each}} helper
I have a simple JavaScript Array object containing a few numbers. [267, 306, 108]
I have an array like this: object[] args and need to insert those args
I have converted an array to object data like this: <?php $myobject->data = (object)Array('zero','one','two');
i have printed out the contents of an array/object (named 'document') with print_r. it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.