【问题标题】:sailsjs standalone action to view (Sailsjs V1.0.0)Sailsjs 独立动作查看(Sailsjs V1.0.0)
【发布时间】:2019-07-18 08:29:46
【问题描述】:

我有一个独立的操作,我通过使用 CloudSDK 单击按钮从前端调用它,我得到了我的值,但该操作不会重定向到视图。我已在成功退出中将 responseType 指定为视图,但这似乎不起作用。

page.js 文件中的按钮代码:

clickVerifyBtn: async function(uid) {

  await Cloud.userIdVerify(uid);
},

动作

module.exports = {


  friendlyName: 'User id verify',


  description: '',


  inputs: {
    uid: {
      description: 'Id of the user',
      type: 'number'
    },   
  },

    exits: {

      success:{
        responseType: 'view',
        viewTemplatePath: 'pages/admin/verification-doc',
      }

    },



  fn: async function (inputs, exits) {

    // All done.
    var userdoc = await Photo.findOne({ownerId: inputs.uid, isRemoved:false, photoType:0})
    var imageSrc = '/images/useruploads/'+userdoc.imageFileName;

    return exits.success({imageSrc: imageSrc});


  }


};

实现这一目标的正确方法是什么?我应该通过 Sails 中捆绑的 ajax-form 组件将我的值提交给操作吗?

非常感谢任何帮助。

【问题讨论】:

    标签: javascript node.js model-view-controller sails.js


    【解决方案1】:

    action2 不是将变量直接返回给视图,而是返回给视图的页面实例(your_view.page.js)提交的方法。

    【讨论】:

    • 感谢您的意见罗伯蒂诺!这里的问题是在运行操作后实际重定向并将结果返回到新视图,不一定是调用操作的视图。因此,我从视图 A 调用操作,但我希望将结果返回给视图 B。
    • 我已经接受了这个答案,因为它确实把我推向了正确的方向,只是理解 res 对象和sailsjs 正在使用它的上下文。
    • 是的,几个月前我开始使用sailsjs,经历了和你一样的经历,很多试验和错误:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 2014-11-10
    • 1970-01-01
    相关资源
    最近更新 更多