在here。
该指令定义为(typescript):
export class OfferingsTableDirective implements ng.IDirective {
...
public scope: OfferingScope;
public templateUrl = "src/directives/templates/offeringsTableDirective.html";
constructor (private $filter: ng.IFilterService) {
this.restrict = "E"; // Element
this.replace = true;
this.scope = <OfferingScope>{ // line 132
offerings : "=offerings"
};
//console.log(this.$filter("orderBy")( this.scope.offerings, ["-price"])); // line 234
}
....
}
最后当我在html页面上使用passng offerings
作为属性时,它会起作用 - 在表格中呈现对象的价格:
但是当我取消注释这一行(234)时:
//console.log(this.$filter("orderBy")( this.scope.offerings, ["-price"]));
结果我看到:["=", "o", "f", "f", "e", "r", "i", "n", "g", "s"]
但不是我从html传递的对象数组[{"price": 1}, {"price" : 2}]
。
问题,我如何才能达到指令属性的目标才能对它们进行排序? (在IDE上它也在第123行抱怨 - 它不喜欢字符串)。但正如我在UI上所说的那些对象渲染(这意味着它们最终会被对象填充)。
更新
link = (scope: OfferingScope, element: ng.IAugmentedJQuery, attrs: OfferingsTableAttrs) => {
var sorted = this.$filter("orderBy")( scope.offerings, ["-price"]);
angular.copy(/*from=*/sorted, /*to=*/scope.offerings);
};
问题在于scope.offerings
,但它没有在ui上表示。没有对产品表进行排序。
<tr ng-repeat="offering in offerings">
<td>{{offering.price}}</td>
<td>source1</td>
</tr>
(我无法复制到this.scope.offerings:angular.copy(/*from=*/sorted, /*to=*/this.scope.offerings);
,因为this.scope.offerings是带有“= offering”值的字符串)