[1.5.2] Editor.Profile 的 api 不能用了

如题,按照官方文档中使用 Editor.Profile.load 等 api 出错,不知道怎么保存扩展用的数据。

        // register a project profile
        Editor.Profile.register('project', '~/foo/bar');

        // load the profile at ~/foo/bar/foobar.json
        //let profile = Editor.loadProfile('profile://project/foobar.json', {
        let profile = Editor.Profile.load('profile://project/foobar.json', {
            foo: 'foo',
            bar: 'bar',
        });

        // change and save your profile
        profile.foo = 'hello foo';
        profile.save();

       // TypeError: Editor.loadProfile is not a function
      // Error: ENOENT: no such file or directory, open '~/foo/bar/foobar.json'

@jare @panda 求帮助。

我是直接使用了fs模块:

 
      var fs = require('fs'),
      path = require('path');

      //保存文件,name为文件名,str是要保存数据(字符串),目录在插件包根目录下,
      fs.writeFile(__dirname+"/"+name+".txt",str,function (err) {
                if (err) throw err ;
                Editor.log("文件保存成功"); 
                }) ;

      //读取文件
      fs.readFile(__dirname+"/"+name+".txt",'utf-8',function(err,str){  
                 if(err){  
                 Editor.log("error");  
                 }else{  
                       //Editor.Scene.callSceneScript('0720', 'import-label-string',id,str, function (err) {
                       //再通过 callSceneScript 把保存的字符串传回节点
                       //});        
                 }  
                 });

不知道是否对你有帮助。

1赞

嗯,当然是可以,谢谢你,我本来想用 Profile 的相关 api 而已。

我不懂你的描述是什么?报错信息是这个吗?

好像并没有 Editor.loadProfile 这个 API 吧,你是在哪里看的能不能给我链接

在这里看到的,我换成 Editor.Profile.load 一样不知道内部怎么使用,文档没有。