Pregunta

Tratando de resolver este concepto. Si console.log this.get ("contenido") antes y después del tipo, todo parece que funcionó, pero cuando se muestra en la pantalla se vuelve funky. Creo que el problema es con el manillar. Cuando "clasifica" agrega un cuarto registro duplicado y lo pega en la parte superior. Puedes ver el problema en acción aquí:

http://jsfiddle.net/skinnehejoe/qpkz5/78/ (Haga clic en el texto 'Ordenar por edad' un par de veces para recurrir a los registros y verá los problemas)

¿Estoy haciendo algo mal, ¿hay una mejor manera o es un error? Si es un error, ¿hay una buena solución?

Aquí está el código completo:

index.html

    <script type="text/x-handlebars">
    {{#view App.SortView}}Sort by Age{{/view}}<br/>

    {{#each App.userController}}
        {{#view App.RecordView contentBinding="this"}}
            {{content.name}} - {{content.age}}
        {{/view}}
    {{/each}}
    </script>

app.js

window.App = Ember.Application.create();

App.userController = Ember.ArrayController.create({
    content: [
        Ember.Object.create({ name:"Jeff", age:24 }),
        Ember.Object.create({ name:"Mark", age:32 }),
        Ember.Object.create({ name:"Jim", age:12 })
    ],
    sort:"desc",
    sortContent:function() {

        if (this.get("sort") == "desc") {
            this.set("sort", "asc");
        } else {
            this.set("sort","desc")
        }

        if (this.get("sort") == "asc") {
            var sortedContent = this.get("content").sort( function(a,b){
                return a.get("age") - b.get("age");
            })
        } else {
            var sortedContent = this.get("content").sort( function(a,b){
                return b.get("age") - a.get("age");
            })
        }

        this.set("content", []);
        this.set("content",sortedContent)
    }
})

App.RecordView = Ember.View.extend({})

App.SortView = Ember.View.extend({
    click: function() {
        App.userController.sortContent("poId")
    }
})
¿Fue útil?

Solución

No estoy viendo este error en Safari, Chrome o Firefox en OS X, así que supongo que es un problema de IE.

Suena mucho como Este error de Ember informó, que se solucionó hace 11 días. Intente actualizar a protuberancia y vea si eso lo arregla.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top