有人可以告诉我如何访问以下扩展程序中的asc
变量进行数据绑定吗?
HTML
示例css
绑定:
<th><a href="#" data-bind="sort: { arr: myArray, prop: 'myProp' }, css: { 'up_chevron': sort.asc, 'down_chevron': !sort.asc }">Performance</a></th>
敲除
ko.bindingHandlers.sort = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var asc = true;
element.style.cursor = 'pointer';
element.onclick = function () {
var value = valueAccessor();
var prop = value.prop;
var data = value.arr;
asc = !asc;
if (asc) {
data.sort(function (left, right) {
return left[prop] == right[prop] ? 0 : left[prop] < right[prop] ? -1 : 1;
});
} else {
data.sort(function (left, right) {
return left[prop] == right[prop] ? 0 : left[prop] > right[prop] ? -1 : 1;
});
}
}
}
};
答案 0 :(得分:0)
尝试
asc()
像这样:
css: { 'up_chevron': sort.asc(), 'down_chevron': !sort.asc() }
答案 1 :(得分:0)
使其成为处理程序对象的成员:
ko.bindingHandlers.sort = {
asc: true,
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var self=this;
...
self.asc = !self.asc;
if (self.asc) {
...