How to create input name field with string-variable schema in Vue Js?

前端 未结 2 568
陌清茗
陌清茗 2021-02-08 00:50

I use VueJs, i need to extract javascript variable to generate hidden fields.

But i need to set the name by the index of the variable.

I want to use zig-zag nami

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-08 01:12

    I ran across the same problem as you, and here is how i fixed it !

    make a method like this in your vue-instance

    getInputName(index, dataName){
          return "items["+index+"]["+dataName+"]";
        }    
    

    then you can use it like this:

    
    
    

    which will give you this post result:

    "items" =>[
        0 =>[
          "name" => "test"
          "price" => "23"
        ],
        1 =>[
          "name" => "jakke"
          "price" => "99,2312"
        ]
    ]
    

    And thats it...

    Cheers, Sipman

提交回复
热议问题