Javascript 静态文件更新时是否重新加载静态文件?
我正在使用CKEditor和AngularJS进行内联编辑(使用contenteditable)。 在CKeditor模糊时,一个$http请求到达服务器并更新数据库,特别是刚刚修改的相关字符串的翻译键/值对 在服务器上,数据库中的字符串更新之后,会触发生成系统,并通过轮询数据库重写[lang].json(静态文件) 如何让angular translate重新加载[lang].json 我看到了很多关于部分重新加载的页面,但是我没有找到任何关于重新加载静态文件的信息 这是指令的作用Javascript 静态文件更新时是否重新加载静态文件?,javascript,angularjs,angular-translate,Javascript,Angularjs,Angular Translate,我正在使用CKEditor和AngularJS进行内联编辑(使用contenteditable)。 在CKeditor模糊时,一个$http请求到达服务器并更新数据库,特别是刚刚修改的相关字符串的翻译键/值对 在服务器上,数据库中的字符串更新之后,会触发生成系统,并通过轮询数据库重写[lang].json(静态文件) 如何让angular translate重新加载[lang].json 我看到了很多关于部分重新加载的页面,但是我没有找到任何关于重新加载静态文件的信息 这是指令的作用 .dir
.directive('frontOfficeEdit', [
// RESTIntranet IS AN ANGULAR FACTORY COMMUNICATING WITH THE REST API
'$rootScope',
'$parse',
'RESTIntranet',
'$translate',
'$filter',
function (
$rootScope,
$parse,
RESTIntranet,
$translate,
$filter
) {
var counter = 0,
prefix = '__ckd_';
return {
restrict: 'A',
link: function (scope, element, attrs, controller) {
// editMode IS A BOOLEAN DECLARED INTO THE DIRECTIVE'S PARENT $scope.
scope.$watch('editMode', function(newVal, oldVal) {
if (!newVal) // IF editMode IS SET TO FALSE (OFF)
{
// REMOVE contenteditable FROM ELEMENT
attrs.$set('contenteditable', false);
// DESTROY ALL CKEDITOR INSTANCES AS SOON AS USER TURNS OFF editMode IN THE GUI.
// THERE CAN BE MULTIPLE CKEDITOR INSTANCES ON THE SAME PAGE, SO, TO MAKE SURE, DESTROY ALL.
for(name in CKEDITOR.instances)
{
CKEDITOR.instances[name].destroy();
}
return;
}
else // ELSE, editMode IS SET TO TRUE (ON)
{
var getter = $parse(attrs.frontOfficeEdit),
setter = getter.assign;
attrs.$set('contenteditable', true); // inline ckeditor needs this
if (!attrs.id) {
attrs.$set('id', prefix + (++counter));
}
var options = {};
// ON BLUR, SAVE CKEDITOR'S CONTENT TO REMOTE DB (REST API)
options.on = {
blur: function (e) {
if (e.editor.checkDirty()) {
var ckValue = e.editor.getData();
// TRANSLATE IT?
ckValue = $filter('translate')(ckValue);
scope.$apply(function () {
console.log('--->@{369} ckValue is going to be inserted/updated in DB through service : ');
console.log(ckValue);
// CB FRAMEWORK INTRANET REST API CALL
RESTIntranet.saveContent(ckValue, attrs.stringid, attrs.stringname);
// UPDATE THE STRING IN STRINGS (JSON)
current_language = $translate.use();
curlang_caps = current_language.toUpperCase();
stringname = attrs.stringname;
// THIS ENSURES THAT SCOPE'S OBJECT IS SET TO THE PROPER VALUE, EVEN ONCE CKEDITOR ARE DESTROYED
/*
————————— BUT THEN, IF I CHANGE FROM EN TO FR, AND THEN GO BACK TO FR, THE TEXT IS AS BEFORE
*/
setter(scope, ckValue);
});
ckValue = null;
e.editor.resetDirty();
}
}
};
options.extraPlugins = 'sourcedialog,find';
options.removePlugins = 'sourcearea';
var editorangular = CKEDITOR.inline(element[0], options); //invoke
scope.$watch(attrs.frontOfficeEdit, function (value) {
// TRANSLATE IT?
value = $filter('translate')(value);
editorangular.setData(value);
});
} // - EOF - else
}, true); // - EOF - scope.$watch('editMode', function(newVal, oldVal) {
}
// - EOF - link
}
// - EOF - return
}]);
我没有足够的javascript经验,不知道挂接到哪里以及如何挂接(还没有足够的异步经验)。谢谢。我想你只需要做一个
$translate.refresh()
但是我需要先更新密钥/值对,不是吗?如何更新转换表本身中的键/值对?因为没有它,它会重新加载“旧”(实际上是当前)值。我还阅读了$translate.instant,我将它们插入发送post HTTP请求的ckedit“blur”中,但没有成功。
* @description
* Refreshes a translation table pointed by the given langKey. If langKey is not specified,
* the module will drop all existent translation tables and load new version of those which
* are currently in use.
*
* Refresh means that the module will drop target translation table and try to load it again.
*
* In case there are no loaders registered the refresh() method will throw an Error.
*
* If the module is able to refresh translation tables refresh() method will broadcast
* $translateRefreshStart and $translateRefreshEnd events.
*
* @example
* // this will drop all currently existent translation tables and reload those which are
* // currently in use
* $translate.refresh();
* // this will refresh a translation table for the en_US language
* $translate.refresh('en_US');