使用Knockoutjs显示Laravel模型关系

时间:2015-07-27 22:18:47

标签: javascript php laravel knockout.js relationship

我需要这方面的帮助。我有这个名为“Title”的模型,其中包含:

public function season()
{
    return $this->hasMany('Season')->orderBy('number', 'asc');
}

和季节模型:

public function title()
{
    return $this->belongsTo('Title');
}

对于我在Laravle的看法,这就是我目前所拥有的:

<section data-bind="foreach: sourceItems" class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
    <figure class="col-xs-6 col-sm-4 col-md-3 col-lg-2 pretty-figure" data-bind="attr: { data: $index }" ontouchstart="this.classList.toggle('hover');">
        <div class="card-container">
            <div class="flip-container">
                <div class="flipper">
                    <a data-bind="attr: { href: vars.urls.baseUrl+'/'+vars.trans[type]+'/'+id+'-'+title.replace(/\//g, '-').replace(/\s+/g, '-').toLowerCase() }" class="front"><img class="img-responsive lazyload" data-bind="attr: { 'data-src': poster, src: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC', alt: title }"></a>
                    <div class="title-mini-stat" data-bind="text: status"></div>
                    @include('Titles.Index.ForEachMovie')
                    <a data-bind="attr: { href: vars.urls.baseUrl+'/'+vars.trans[type]+'/'+id+'-'+title.replace(/\//g, '-').replace(/\s+/g, '-').toLowerCase() }, text: plot ? plot.trunc(800) : null" class="back"></a>
                </div>
            </div>
            <figcaption>
                <a class="series-name" data-bind="attr: { href: vars.urls.baseUrl+'/'+vars.trans[type]+'/'+id+'-'+title.replace(/\//g, '-').replace(/\s+/g, '-').toLowerCase() }, text: title"></a>
                </div>
            </figcaption>
        </div>
    </figure>
</section>

这基本上显示了可用的标题列表:我需要做什么才能让模型关系显示在Knockoutjs上?

0 个答案:

没有答案