Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't loop an Object-Array with ember #each

<div class="nav-menu clearfix">
    <ul class="list-unstyled list-inline">
        {{#each MI in MB}}
            <li id=""><span>{{ MI.MText }}</span></li>
        {{else}}
            {{MB}}
        {{/each}}
    </ul>
</div>

I want loop the MB with each.

but it dose not work and return the MB is empty.

but I get this for else.

[object Object],[object Object],[object Object],[object Object],[object Object]

this is my route define

//application路由
App.ApplicationRoute = Ember.Route.extend(App.LazyLoadTemplate, {
    model : function() {
        return Ember.$.getJSON("/index/indexjson");
    }
});

and get a json data is

{
    'UIB':{...},
    'MB':[{...},{...},...,{...}]
}

My English is not well ,Thanks for help!

like image 301
xmmwc Avatar asked Jan 21 '26 01:01

xmmwc


1 Answers

As you already found, your scope of your property was incorrect. Just to set the record straight, Ember-Handlebars will not iterate over an object like it will over an Array. Additionally the else statement is totally legit, it will be triggered when the array being iterated across is empty (null/undefined/no elements)

{{#each item in model}}
   {{item}}
{{else}}
   No Items
{{/each}}

http://emberjs.jsbin.com/iWohUlE/1/edit

like image 124
Kingpin2k Avatar answered Jan 22 '26 18:01

Kingpin2k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!