1

私はこのようなものを持っています:

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


App.Person = Ember.Object.extend({
    id: null,
    firstName: null,
    lastName: null,

    fullName: function() {
        return this.get('firstName') + " " + this.get('lastName');
    }.property('firstName', 'lastName')
});

App.selectedPersonController = Ember.Object.create({
    person: null
});

App.selectedChildrenController = Ember.Object.create({
    person: null
});

App.peopleController = Ember.ArrayController.create({
    content: [
        App.Person.create({
        id: 1,
        firstName: 'John',
        lastName: 'Doe'
    }),
        App.Person.create({
        id: 2,
        firstName: 'Tom',
        lastName: 'Cruise'
    }),
        App.Person.create({
        id: 3,
        firstName: 'Peter',
        lastName: 'Pan'
    }),
        App.Person.create({
        id: 4,
        firstName: 'Sergey',
        lastName: 'Brin'
    })
        ]

});

App.childrenController = Ember.ArrayController.create({
    children: [
        App.Person.create({
        person_id: 1,
        firstName: 'Scott',
        lastName: 'Hall'
    }),
        App.Person.create({
        person_id: 1,
        firstName: 'Jim',
        lastName: 'Can'
    }),
        App.Person.create({
        person_id: 2,
        firstName: 'Will',
        lastName: 'Smith'
    }),
        App.Person.create({
        person_id: 4,
        firstName: 'Bale',
        lastName: 'Ron'
    })
        ],
    active: function() {
        if (App.selectedPersonController.person) {
            return this.get("children").filterProperty("person_id", App.selectedPersonController.person.id);
        }
        else {
            return null;
        }
    }.property("App.selectedPersonController.person").cacheable()

});


window.App.Select = Ember.Select.extend({
    contentChanged: function() {
        this.$().selectBox('destroy').selectBox();
    }.observes('content')

});

私のビューコードは次のようなものです:

<script type="text/x-handlebars">
  {{view window.App.Select
         contentBinding="App.peopleController"
         selectionBinding="App.selectedPersonController.person"
         optionLabelPath="content.fullName"
         optionValuePath="content.id"
         prompt="Pick a person:"}}

     {{view window.App.Select
         contentBinding="App.childrenController.active"
         selectionBinding="App.selectedChildrenController.person"
         optionLabelPath="content.fullName"
         optionValuePath="content.id"
         prompt="Pick a child:"}}

  <p>Selected: {{App.selectedPersonController.person.fullName}}
    (ID: {{App.selectedPersonController.person.id}})</p>

</script>

最初の window.App.Select での選択に応じて、2 番目の window.App.Select が動的に更新されるようにします。2 番目の window.App.Select にcontentBinding="App.childrenController.active"を使用してこれを機能させていますが、人の選択ボックスで値を選択すると、選択したときに子選択ボックスが更新されません人物選択ボックスとは別の人 子選択ボックスには、人物選択ボックスでの以前の選択に応じて、フィルタリングされた値が入力されます。

Person selectbox -> select = John Doe (何も起こらない)

Person selectbox -> select = Tom Cruise (子の選択ボックスは「John Doe」の選択に従ってフィルタリングされます)

等々。

何が悪いのか見てください。

4

1 に答える 1

3

ember.js/1.0.0-rc3 を使用して、連鎖または依存するこのバージョンの選択ボックスを実装して、Rajat のデッド リンクを動作中の jsbin に復元しようとして、すべてを再びまとめました。

http://jsbin.com/ixogag/5/

于 2013-05-07T13:18:02.130 に答える