2015-12-13 22 views
10

Tôi có biểu mẫu được tạo thông qua v-cho.Tên mô hình v/tính năng động bên trong v-cho

Lưu ý: Tôi đang sử dụng "@" để thoát khỏi lưỡi dao.

vue isstance của tôi có:

data: { 
    form: { 
     inputs: [{icon: "", name="", placeholder: "", type="", value=""}] 
    }, 
    owner: {first_name: "", last_name: "", cell_phone: "", email: ""} 
} 

tôi tạo mẫu với:

<template v-for="input in form.inputs"> 
    <div style="margin-bottom: 25px" class="input-group"> 
     <span class="input-group-addon"><i class="glyphicon [email protected]{{input.icon}}"></i></span> 
     <input id="[email protected]{{input.name}}" v-model="?????" type="@{{input.type}}" class="form-control" name="@{{input.name}}" placeholder="@{{input.placeholder}}"> 
    </div> 
</template> 

Tôi muốn ràng buộc mỗi đầu vào đối với tài sản nhà thầu tương ứng của họ. Vì vậy, tôi muốn các giá trị v-mô hình là owner.first_name, owner.last_name, owner.cell_phone và chủ sở hữu. e-mail. Tôi đã hy vọng tôi có thể làm:

v-model="'owner' + @{{input.name}}" 

Nhưng tôi nhận được:

[Vue warn]: v-model="'owner' + {{input.name}}": attribute interpolation is not allowed in Vue.js directives and special attributes. 
vue.js:1956 Error: Warning Stack Trace 
    at warn (vue.js:1956) 
    at Directive.bind (vue.js:4507) 
    at Directive._bind (vue.js:8668) 
    at linkAndCapture (vue.js:7367) 
    at compositeLinkFn (vue.js:7345) 
    at new Fragment (vue.js:5373) 
    at FragmentFactory.create (vue.js:5575) 
    at Directive.create (vue.js:5844) 
    at Directive.diff (vue.js:5757) 
    at Directive.update (vue.js:5692) 

Các đặc tính chủ sở hữu tương ứng với input.name cho mỗi đầu vào.

Cảm ơn

Mô tả ứng dụng: Tôi đang cố gắng xây dựng chủ sở hữu bằng nhiều hình thức. Mỗi biểu mẫu được tạo thông qua yêu cầu ajax nhận đối tượng biểu mẫu chứa các đầu vào n và hành động cho biểu mẫu đó.

Trả lời

16

Bạn có thể thử này:

v-model="owner[input.name]" 
+0

này làm việc! Cảm ơn bạn! – Deciple

Các vấn đề liên quan