>  Q&A  >  본문

angular.js - 请问关于AngularJS里数组对象的使用例子问题

 self.getNoteClass = function(status) {
    return {
        done: status,
        pending: !status
    };
  };  

我在书中遇到这样一个用法,传入参数必须是true或false,然后传入true就是返回done,false就是返回pending。
我想问下这种用法是angularjs里的特殊用法吗?表示不理解,请大神解答,谢谢!
PS:下面这个我自己写的例子是我比较能理解的一个较简单清楚的使用方式。

self.getClassname = function(string) {
    var obj = {
      '1' : even,
      '2' : odd
    };
    return obj[string];
  };
PHP中文网PHP中文网2714일 전599

모든 응답(1)나는 대답할 것이다

  • 天蓬老师

    天蓬老师2017-05-15 16:52:09

    이것은 ng-class 내장 지시문과 함께 사용하기 위한 것 같습니다. 이 경우 className done은 < code>status는 true이고 그렇지 않으면 className pending이 요소에 적용됩니다.ng-class built-in directive, in which case, the className done will be applied to the element when status is true, and className pending will be applied to the element otherwise.

    You may see the "Map Syntax Example" section in the document for ng-class

    ng-class에 대한 문서에서 "맵 구문 예" 섹션을 볼 수 있습니다. 참고로.🎜

    회신하다
    0
  • 취소회신하다