评论的部分位于 $ 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;
//}
}
}
答案 0 :(得分:2)
我不确定我理解你的问题,但是如果我这样做,你需要从 $ 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('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);
}
})
答案 1 :(得分:0)
我认为您可以使它比其他答案更简单,只需调整指令中的数据,然后将其用作返回值即可。
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
}