注释部分将位于$scope.$on下。我需要将选项返回到我保存$scope.$emit的地方。请帮忙
!!if (gridConfig.Batch) {
gridOption.dataSource.transport["parameterMap"] = function (options, operation) {
var data = {
options: options,
operation: operation
};
$scope.$emit('parameterMap', data);
//if (operation !== "read" && options.models) {
// angular.forEach(options.models, function (value) {
// value.MfgDt = kendo.toString(value.MfgDt, "s");
// value.ExpDt = kendo.toString(value.ExpDt, "s");
// value.ProductType = value.ProductType.Id;
// })
// return options;
//}
}
}
我不确定我是否理解你的问题,但如果我理解,你想要一个从你的$scope.$on到你的$scope.emit的回调函数。如果是这样,下面的代码将为您提供帮助,请告诉我它是否有效,因为我还没有测试过它。
if (gridConfig.Batch) {
gridOption.dataSource.transport["parameterMap"] = function (options, operation) {
var data = {
options: options,
operation: operation
};
$scope.$emit('parameterMap', data,function(returnedData){
//returnedData.options = the updated options
});
}
}
$scope.$on:
$scope.$on('parameterMap', function (e, data,callback) {
if (data.operation !== "read" && data.options.models) {
angular.forEach(options.models, function (value) {
value.MfgDt = kendo.toString(value.MfgDt, "s");
value.ExpDt = kendo.toString(value.ExpDt, "s");
value.ProductType = value.ProductType.Id;
})
callback(data);
}
})
我认为你可以让它比其他答案简单得多,只需调整指令中的数据,并将其用作返回值。
if (gridConfig.Batch) {
gridOption.dataSource.transport["parameterMap"] = function (options, operation) {
var data = {
options: options,
operation: operation
};
$scope.$emit('parameterMap', data);
// by the time we reach here the directive
// will have altered the data object
if (data.operation !== "read" && data.options.models) {
angular.forEach(options.models, function (value) {
value.MfgDt = kendo.toString(value.MfgDt, "s");
value.ExpDt = kendo.toString(value.ExpDt, "s");
value.ProductType = value.ProductType.Id;
})
return options;
}
}
}
在指令中:
$scope.$on('parameterMap', function (e, data) {
data.operation = "write" ;
data.options = {models: 'something here'}
// do something else here, whatever the purpose of the directive is
}