Javascript 对不同的数据使用相同的指令
我对Angular指令有点陌生,我想知道是否有一种方法可以多次使用同一指令,但绑定不同的数据?(我确信有一种方法我就是不知道怎么做!) 例如,我有以下两个表,我想将它们转换为1指令,并以不同的方式传入数据: 1.这里我通过一个对象数组重复,如果kv isPaint:true,那么我将打印下表Javascript 对不同的数据使用相同的指令,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,我对Angular指令有点陌生,我想知道是否有一种方法可以多次使用同一指令,但绑定不同的数据?(我确信有一种方法我就是不知道怎么做!) 例如,我有以下两个表,我想将它们转换为1指令,并以不同的方式传入数据: 1.这里我通过一个对象数组重复,如果kv isPaint:true,那么我将打印下表 <tr class="hover" ng-repeat="paint in allOptions | orderBy: 'listPrice'" ng-if="paint.isPa
<tr class="hover"
ng-repeat="paint in allOptions | orderBy: 'listPrice'"
ng-if="paint.isPaint"
ng-click="addRemoveOption(paint)"
ng-class="{'selected':isSelected(paint)}"
>
<td> {{ paint.code }}</td>
<td> {{ paint.name }}</td>
<td> {{ paint | includedOption }}</td>
<td> {{ paint.disclaimer }}</td>
<td> {{ paint.salesGroup }}</td>
<td> {{ paint.optionPrev}}</td>
<td> {{ paint.familyCode }}</td>
</tr>
{{paint.code}
{{paint.name}
{{paint | includedOption}}
{{paint.disclaimer}}
{{paint.salesGroup}
{{paint.optionPrev}}
{{paint.familyCode}
<tr class="hover"
ng-repeat="trim in allOptions | orderBy: 'listPrice'"
ng-if="trim.isTrim"
ng-click="addRemoveOption(trim)"
ng-class="{'selected':isSelected(trim)}"
>
<td> {{ trim.code }}</td>
<td> {{ trim.name }}</td>
<td> {{ trim | includedOption }}</td>
<td> {{ trim.disclaimer }}</td>
<td> {{ trim.salesGroup }}</td>
<td> {{ trim.optionPrev }}</td>
<td> {{ trim.familyCode }}</td>
</tr>
{{trim.code}
{{trim.name}
{{trim | includedOption}}
{{trim.disclaimer}}
{{trim.salesGroup}
{{trim.optionPrev}}
{{trim.familyCode}
感谢您的帮助,如果我能提供任何其他信息,请告诉我。重复列表的简单指令:
app.directive('myDirective', function($compile) {
return {
restrict: 'E',
scope: {
list: '='
},
template: '<div ng-repeat="item in list">{{item.name}}</div>',
replace: true,
//require: 'ngModel',
link: function($scope, elem, attr, ctrl) {
}
};
});
app.directive('myDirective',函数($compile){
返回{
限制:'E',
范围:{
列表:'='
},
模板:“{item.name}}”,
替换:正确,
//要求:'ngModel',
链接:函数($scope、elem、attr、ctrl){
}
};
});
这是一个
这应该可以让您开始了。我必须稍微更改一下我的数据模型,以使其工作正常,但我相信这是正确的答案。但是,我可能应该这样开始我的数据模型:)。再次感谢!