0

アンダースコア付きのmobiscrollを使用しています。アンダースコア テンプレートがあります。テンプレートから追加された要素で .scroller を実行する必要があります。

テンプレートは次のとおりです。

<form>
    <input type="text" id="startdate" name="startdate"/>
</form>

ビューのレンダリング関数は次のとおりです。

var MyView = Backbone.View.extend({
    template: render('auctioncreate'),
    render: function() {
        this.$el.empty().append(this.template);
        $('#startdate').scroller();  // this does not work
    }
});

render は html を読み込んでテンプレートにする関数です。完全を期すために、render 関数のコードを次に示します。

function render(tn, td) {
    if(!render.tc) {
        render.tc = {};
    }
    if(! render.tc[tn]) {
        var td = 'assets/js/templates';
        var tu = td + "/" + tn + ".html";
        var ts;
        $.ajax({
            url: tu,
            method: 'GET',
            async: false,
            dataType: 'html',
            success: function(d) {
                ts = d;
            },
            error: function(e) {
            }
        });
        render.tc[tn] = ts;
    }
    return _.template(render.tc[tn]);
}

テンプレート自体に ondomready JavaScript を追加しようとしました。すぐには効かないけど、リフレッシュしたら効く!?

$(function() {
    $('#startdate').scroller(); // this work if I refresh once.
});

基本的に、要素がdomに追加された後、要素に日時ピッカーを適用する必要があります。

4

1 に答える 1

1

ビューのレンダリング機能にエラーがありました。

それ以外の:

$('#startdate')...

次のようになっているはずです。

this.$('#startdate')...
于 2012-09-30T20:18:59.467 に答える