LoginSignup
2
2

More than 5 years have passed since last update.

Ractive.jsで別のライブラリの関数(たとえばBootstrapのdatepicker)を使う方法

Last updated at Posted at 2015-09-16

表題の件、Ractive.jsでデータ表示したあと、UI上で変更しても保持しているdataが更新されなくて困ったので。

こんな感じで書いた。

var ractive = new Ractive({
            el: '#element',
            template: '#template',
            data: {data: data},
            decorators: {
                datepick: function(node){
                    var rct = this
                    $(node).datepicker({
                        format: 'yyyy/mm/dd',
                        language: 'ja',
                        autoclose: true,
                        todayHighlight: true,
                        }).on('changeDate',function(dateValue) {
                        rct.updateModel();
                    });
                    return{
                        teardown: function(){
                            $(node).datepicker("destroy");
                        }
                    };
                }
            },
        });

公式リファレンス
http://docs.ractivejs.org/latest/writing-decorator-plugins

デモ(tooltipの場合)
http://jsfiddle.net/tomByrer/9g3pB/11/

teardownっていうメソッド無いとおこられるです。かわいいかとw

※上記ソースのdetepickerのイベント名が違っていたのを修正(2015/11/02)

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2