0

ajax を介して配列オブジェクトを取得し、それを ui コンポーネントに送信して表示するデータ コンポーネントがあります。アプローチとして、配列全体を送信するのではなく、データ コンポーネント内の配列をトラバースし、各要素を ui コンポーネントに送信する方法があります。

エラーが発生しています: Uncaught TypeError: undefined is not function on the line: ths.trigger('dataAdded', value); (下記参照)

データ コンポーネントがドキュメントに添付されます。

this.handleData = function(){
      var ths = this;
        $.ajax({            
        "url": 'url',
        "type": "get",
        "dataType": "json",
        "success": function(data) {
            $.each(data, function(index, value){
                ths.trigger('dataAdded',  value);
            });
        },
        "error": function(jqXHR, status, error) {
            console.log("status:", status, "error:", error);
           // return;
      }
        });
    };
4

2 に答える 2

0

「.bind(this);」を追加 終わりの $.each 中かっこまで。

this.handleData = function(){
      $.ajax({            
        "url": 'url',
        "type": "get",
        "dataType": "json",
        "success": function(data) {
            $.each(data, function(index, value){
                this.trigger('dataAdded',  value);
            }.bind(this);
        },
        "error": function(jqXHR, status, error) {
            console.log("status:", status, "error:", error);
           // return;
      }
        });
    };

...

this.after('initialize', function() {

}
于 2014-04-25T14:55:03.870 に答える