N
N
nastya_zholudeva2018-09-24 15:56:38
Vue.js
nastya_zholudeva, 2018-09-24 15:56:38

How can such an object be created through v-model?

How can such an object be created through v-model? where index is a randomly generated number. In fact, you need to create an object of objects, each element of which has a property - a random number, a value - v-model="entity[index].name" An example is here
entity = {index: entity[index].name}

Answer the question

In order to leave comments, you need to log in

5 answer(s)
K
Klein Maximus, 2018-09-27
@nastya_zholudeva

1) entity[index].namewill not be reactive, because initially such a value did not exist, and you need to use it - v-model will not work the model passed in the parameter (in fact, this is the "syntactic sugar" that is called v-model). 3) hang up an event on a component with a field and form it in the method. $set
{ entity[xxx].yyy }

M
marazmiki, 2015-05-07
@Scirocco

Add a list of slides to the template context:

# views.py
def slider(request):
    slides = Slide.objects.all()
    return render(request, 'main.html', {'slides': slides})
and in the template refer to each of the list slides
{# main.html #}
{% for slide in slides %}
<div class="item lifted">
    <img class="lazyOwl" data-src="{{ slide.image.url }}">
    <div class="caption-content">
        <h1 class="caption lifted">{{ slide.header }} </h1><br>
        <p class="caption2 lifted">{{ slide.caption }}</p>
    </div>
</div>
{% endfor %}

A
Alexey Sergeev, 2015-05-07
@SergeevAI

Are you running, as I understand it, on the dev server (manage.py runserver)?
If so, then the Django web server does not know how to serve media files itself.
You can try the following in urls.py:

if settings.DEBUG:
    urlpatterns += patterns(
        'django.views.static',
        (r'media/(?P<path>.*)',
        'serve',
        {'document_root': settings.MEDIA_ROOT}), )

www.tangowithdjango.com/book/chapters/templates_st...
And view rewrite
from .models import Slide

def slider(request):
    slides = Slide.objects.all()
    return render(request, 'main.html', locals())

In the view, you do not pass objects to the template, or enclose in a dictionary (context = {"slides": slides} and add context in the render, or pass locals() in the render)

S
sim3x, 2015-05-07
@sim3x

https://docs.djangoproject.com/en/1.8/topics/http/...

views.py
from .models import Slide

def slider(request):
    context = {'slides': Slide.objects.all()}
    return render(
request, 
'main.html',
# context???
context
)

main.html
{% for slide in slides %}
<div class="item lifted">
    <img class="lazyOwl" data-src="{{ slide.image.url }}">
    <div class="caption-content">
        <h1 class="caption lifted">{{ slide.header }} </h1><br>
        <p class="caption2 lifted">{{ slide.caption }}</p>
    </div>
</div>
{%endfor%}

don't use shortcuts without understanding what's behind them
Start with https://docs.djangoproject.com/en/1.8/ref/request-...

Z
zelsky, 2015-05-07
@zelsky

The image file also has url access to the file in the media folder.
{slide.image.url}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question