2017-05-18 6 views
0

私はDBからロードするボックスのリストを持っています。私はdata-orderで注文する注文機能を作ろうとしていますが、ユーザーがボタンをクリックしたときに起動されるはずです。角度:jQueryを使用してデータオーダーによる注文リスト

コンポーネント

import { JQ_TOKEN} from "../../_service/index"; 
constructor(@Inject(JQ_TOKEN) private $: any) {} 

次関数

orderGames() { 
    var boxList = this.$('.box'); 
    var container = this.$('.box-list-container'); 
    boxList.sort(function (a: any, b: any) { 
     return this.$(a).data("order") - this.$(b).data("order"); 
    }); 
    container.html(boxList); 
} 

私は次のエラーの横の受け取り:

EXCEPTION: Error in app/dark-navbar.component.html:44:24 caused by: Cannot read property '$' of undefined

は、どのように私はそれを動作させることができますか?

+0

「this」があることを確認してください。私が推測するのは、それがクラスコンポーネントではないということです。 –

答えて

0

実は私は前の角度では動作しませんでした..しかし、jqueryの関数として、あなたが

orderGames(el) { 
    var boxList = $(el).find('.box'); 
    var container = $(el).find('.box-list-container'); 
    boxList.sort(function (a, b) { 
     return $(a).data("order") - $(b).data("order"); 
    }); 
    container.html(boxList); 
} 

のようなものを使用することができますし、あなたはいけない

orderGames(this) 

Note:.find()Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element... and while I don't know your structure I can't determine which jquery function you will need may be .find() , .prev() , .closest() .. etc

0

のようにそれを使用しますthisが必要です。 jQueryをAngularと併用する方法は次のとおりです。

declare var $: any; 

@Component({ 
    selector: 'some-thing', 
    templateUrl: './template.html' 
}) 

export class ApplicationComponent implements AfterViewInit { 
    public results: String[] = []; 

    public ngAfterViewInit() { 
    $('#offcanvas').click(() => $('.row-offcanvas').toggleClass('active')); 
    } 
} 
+0

'this'を削除すると、"名前 '$'が見つかりません。インスタンスメンバー 'this。$' "を意味しましたか?コメントを付けると 'sort(function(a、b)')に問題があり、divの配列 – Timur

+0

の配列を示しています。

  • 11. グローバルオブジェクトの使用による角度依存性注入の回避
  • 12. 角度注入サービスでカスタムデコレータを使用する方法
  • 13. 角度受注値
  • 14. Camlを使用して注文する
  • 15. 角度cliを使用して角度バージョンを更新
  • 16. 固定リストによるmysqlの注文
  • 17. 角度2は、私は以下のように角度使用してルーティングを実装している
  • 18. RGBデータオーダーを使用するには、cv :: Matを強制してください。
  • 19. JQueryを使って<option select>リストをどのように動的に注文しますか?
  • 20. 角度4 - 角度4を使用してOnChanges内部formcontrol.setValueは、()()
  • 21. 角度CLI - 角度CLIを使用してバンドル
  • 22. 米国の注文ではないパイプを使用している角度4の日付
  • 23. 角度jsを使用してリストを非表示/元に戻す
  • 24. FacebookのフレンドのリストをC#sdkを使用して注文しています
  • 25. 角度2の使用を計画していますが、既存のアプリは角度1.xを使用しています。角度1.xと一緒に角度2を使用することに関する文書はありますか?
  • 26. 角度を使用してクリックしてコンポーネントにスクロールする
  • 27. Page Scrollイベント角度を使用して
  • 28. 角度から見たコントローラから注入を使用
  • 29. SQLを使用してデータを注文
  • 30. jQuery - 再注文Divs通過注文機能を介して