[英]How to show the selected plan value in a text box in vue js html?
My json data is as follows我的json数据如下
{"status": true, "plans": [{"planId": 1, "name": "Baic", "cost": 500.0, "validity": 365}, {"planId": 3, "name": "free", "cost": 0.0, "validity": 999}, {"planId": 4, "name": "Premium", "cost": 500.0, "validity": 500}, {"planId": 5, "name": "Super Premium", "cost": 750.0, "validity": 600}, {"planId": 6, "name": "New", "cost": 600.0, "validity": 180}]}
I need to select a particular category from the above list and display the corresponding cost of the category in a text box and i need to able to edit the value.我需要从上面的列表中选择一个特定的类别,并在文本框中显示该类别的相应成本,我需要能够编辑该值。 How acan I able to obtain the same.
我如何能够获得相同的。
Currently my html code is目前我的 html 代码是
<div class="form-group">
<label>Plan <small>(select your plan)</small></label>
<select id="bas" class="selectpicker" data-live-search="true" data-live-search-style="begins" title="Select Plan" v-model="plan" name="plan" ref="plan" required="required">
<option v-for="post in plansb" v-bind:value="post.planId" v-if="plansb.indexOf(post) > 0">{{post.name}} (Rs.{{post.cost}})</option>
</select>
</div>
<div class="form-group">
<label>Plan Amount <small>(required)</small></label>
<input name="plan_amt" type="text" class="form-control" id="plan_amt" placeholder="Plan Amount" v-model="plan_amt" />
</div>
In the Plan Amount text-box I need to display the cost of which category is selected from the above selection.在计划金额文本框中,我需要显示从上述选择中选择哪个类别的成本。 Now I need to enter the amount.
现在我需要输入金额。 IF is selected planId = 1, I need to display 500 in the text-box.
如果选择planId = 1,我需要在文本框中显示500。 Also i need to edit those value and send as as ajax request.
我还需要编辑这些值并作为 ajax 请求发送。
How can I able to get the result as such.我怎样才能得到这样的结果。
My vue js code is我的 vue js 代码是
vBox = new Vue({
el: "#vBox",
data: {
plansb: [],
plan: '',
plan_amt: '',
},
mounted: function() {
var vm = this;
$.ajax({
url: "http://127.0.0.1:8000/alpha/get/plan/",
method: "GET",
dataType: "JSON",
success: function(e) {
if (e.status == 1) {
vm.plansb = e.plans;
}
},
});
},
methods: {
handelSubmit: function(e) {
var vm = this;
data = {};
data['plan'] = this.plan;
data['plan_amt'] = this.plan_amt;
$.ajax({
url: 'http://127.0.0.1:8000/alpha/add/post/',
data: data,
type: "POST",
dataType: 'json',
success: function(e) {
if (e.status)
{
$("#alertModal").modal('show');
$(".alert").removeClass("hidden").html("Your data has been successfully recorded");
vm.pid=e.pid;
console.log(vm.pid);
}
else {
vm.response = e;
alert("Registration Failed")
}
}
});
return false;
},
Can anybody please help me to obtain the result.任何人都可以帮助我获得结果。 Based on the selection of plans from the select, I need to update the values in the text box.
根据从选择中选择的计划,我需要更新文本框中的值。 Please help me to have a result.
请帮我出结果。
您需要添加列表的更改事件并获取 palns 的计划,并根据计划获取它的成本并将其分配给您要显示更改计划成本的成本(文本框)模型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.