0

その中のリストを選択するためのフォームがありcountryListますstateList。これらのそれぞれには、コレクションcountrysと「状態」もあります。

選択した国に基づいて、選択した国stateListに属する州のみを表示したいと考えています。

states コレクションにはフィールド country があるので、それに基づいてフィルタリングできます。

stateList????を作成するコードを処理できません。

何時間もの実験と試行錯誤の後、私は次のようになります:

Template.registerPartnerStep2.events({
'click #countryList': function (event, template) {
    var x = myTrim($("#countryList").val());
    var y = (Countrys.findOne({country: x}));
    var z = y.nr;


},
'focus #stateList': function (event, template) {

    event.preventDefault();
    var x = myTrim($("#countryList").val());
    var y = (Countrys.findOne({country: x}));
    var z = y.nr;
    if (typeof(this.stateSub) !== 'undefined') {
        this.stateSub.stop();
    }
    this.stateSub = Meteor.subscribe('stateList', z);

}
})

誰でも私をさらに助けることができますか??

4

2 に答える 2

0
  1. で国を購読しonCreatedます。
  2. 国の変更/クリックのイベントに反応します。
  3. 国が変わったら、州/地域のリストに登録します
  4. 州/地域のリストは、データが到着したときに反応する必要があります。ローカル コレクションにクエリを実行する単純なテンプレート ヘルパーで十分です。
于 2015-05-11T10:30:44.673 に答える
0

セッション使用のための編集:

Template.registerPartnerStep2.events({

    'change #countryList': function () {
        var country = myTrim($("#countryList").val());
        Session.set('selectedCountry', country)
    }

});


Template.registerPartnerStep2.helpers({

    selectedCountryStates: function () {
        var country = Session.get('selectedCountry');
        return States.find({country: country})
    }

});
于 2015-05-11T11:10:14.400 に答える