更新AlpacaJS数据而无需破坏和重新创建

时间:2019-07-18 19:22:06

标签: javascript alpacajs

从他们的tutorial

中考虑以下示例
var data = {
      "name": "Diego Maradona",
      "feedback": "Very impressive.",
      "ranking": "excellent"
  };
$("#form").alpaca({
  "data": data,
  "schema": {
      "title":"User Feedback",
      "description":"What do you think about Alpaca?",
      "type":"object",
      "properties": {
          "name": {
              "type":"string",
              "title":"Name",
              "required":true
          },
          "feedback": {
              "type":"string",
              "title":"Feedback"
          },
          "ranking": {
              "type":"string",
              "title":"Ranking",
              "enum":['excellent','ok','so so'],
              "required":true
          }
      }
  },
  "options": {
      "form":{
          "attributes":{
              "action":"http://httpbin.org/post",
              "method":"post"
          },
          "buttons":{
              "submit":{}
          }
      },
      "helper": "Tell us what you think about Alpaca!",
      "fields": {
          "name": {
              "size": 20,
              "helper": "Please enter your name."
          },
          "feedback" : {
              "type": "textarea",
              "name": "your_feedback",
              "rows": 5,
              "cols": 40,
              "helper": "Please enter your feedback."
          },
          "ranking": {
              "type": "select",
              "helper": "Select your ranking.",
              "optionLabels": ["Awesome!",
                  "It's Ok",
                  "Hmm..."]
          }
      }
  },
  "view" : "bootstrap-edit"
});

function randomFill() {
    data.name = 'something else';
    data.feedback = 'bla bla'
    data.ranking = 'ok';
    // data not reflected back to the alpaca form
}

如何在羊驼毛形式内更新数据属性?而不破坏表单,然后再次重新创建羊驼毛表单。

0 个答案:

没有答案