我有三个下拉菜单来设置唯一订单值。 Html代码: -
return {
restrict: 'EA',
scope: {},
controller: function ($scope) {
$scope.myOrder = {};
$scope.myOrder.step = [];
},
link: function (scope, el, attrs) {
scope.checked = function() {
if (_.uniq(scope.myOrder.step).length !== scope.myOrder.step.length) {
scope.notify("error", "Please set unique order value");
}
};
scope.save = function(isValid) {
if (isValid) {
if (!scope.values) {
ApiServices.updateOrderSet(scope.myOrder).then(function (response) {
scope.notify('success', response.data);
scope.values = false;
});
} else {
ApiServices.updateAddSet(scope.myOrder).then(function (response) {
scope.notify('success', response.data);
});
}
} else {
scope.notify('error', 'There are errors on the form');
}
};
},
在这些下拉列表中,我应用了一个过滤器。 指令代码: -
scope.notify("error", "Please set unique order value");
我想要的是,如果用户在下拉列表中设置相同的值,即不唯一,则在保存按钮上它会通知$submitted
表单也不会提交。请注意,这些不是必填字段。我也试过了if (right, true, true, true):
x++; // Move towards right
else if (left, true, true, true):
x--; // Move towards left
else:
// This is where I stuck. There should be two cases where in one of them
// y goes down and x doesn't change direction, in the other case x simply
// flips its direction. But I wasn't able to figure it out.
但是没有用。任何人都可以告诉我该怎么做才能让它发挥作用。