MongoDB
 sql >> Teknologi Basis Data >  >> NoSQL >> MongoDB

SailsJS:Dapatkan Resonse dari Ajax-Form of SailsJS dalam fungsi yang dikirimkan

Anda benar dalam langkah-langkah yang telah Anda jelaskan di atas, dan saya pikir semua yang Anda lewatkan adalah Anda harus meletakkan parameter give ke fungsi yang Anda kirimkan. Sebagai penyangga dalam template vue, Anda memasukkan ($event). Dalam skrip halaman (nama-halaman.halaman.js) Anda dapat memiliki parameter yang dinamai apa pun yang Anda inginkan di mana Anda mendefinisikan fungsi yang dikirimkan.

Meskipun sepertinya Anda tidak membutuhkannya, saya akan memberikan contoh menyeluruh di sini jika ada orang lain yang mengalami masalah dengan fungsi bentuk ajax di Sails.js.

Di template Anda (html):

<ajax-form
    action="<camelcase of the file for your action>" 
    :handle-parsing="parseForm"
    :submitted="submittedForm($event)"
    @rejected="rejectedForm($event)"
    :form-data="formData"
    :form-rules="formRules"
    :form-errors.sync="formErrors"
    :cloud-error.sync="cloudError"
>
<input type="text" id="input1" v-model="input1">

Di sini, form-data akan merujuk ke objek tempat data disimpan. Kunci akan berasal dari apa yang Anda atur v-model' as for a given input. form-rulesis where you specify an object of objects. They key of each is the input name from v-modeland the value can be a string or array of strings for the rules set. form-errorsspecifies an object where errors will go if the form triggers any errors upon submission. If this happens, data does not get sent to the server and neither the submitted or rejected function get run. cloud-error.sync` menentukan objek tempat kesalahan back-end akan terjadi jika tindakan mengembalikan respons non-200.

Di skrip halaman Anda (nama-halaman.halaman.js):

data: {
    formData: {},
    formErrors: {},
    formRules: {
        input1: 'required'
    },
    cloudError: ''
},
methods: {
    parseForm: function () {
        // You can do parsing and custom validations here, but return all data 
        // you want to send to the server as an object called 'argins'
        return argins;
    },
    submittedForm (data) {
        // Here you can use any data that is returned from the action, like
        console.log('returned data: ', data);
    },
    rejectedForm (err) {
        // This function runs if the server returns a non-200 response
        console.log(err);
    }
}



  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Nodejs tidak dapat terhubung ke mongodb di cloud shell

  2. Node MongoDb { err:'koneksi ke [127.0.0.1:27017] habis waktu' }

  3. MongoDB di Go dengan mgo, operator dengan bson.M / bson.D selalu mendapat kesalahan sintaks

  4. MongoDB:Hitung waktu diam antara setiap perubahan nilai status

  5. Bagaimana cara mengubah kata sandi pengguna MongoDB?