我有两个具有一对多关系的模型。
class User extends ConfideUser {
public function shouts()
{
return $this->hasMany('Shout');
}
}
class Shout extends Eloquent {
public function users()
{
return $this->belongsTo('User');
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常。但是,如何获取返回嵌套在shout对象中的users对象?现在,它仅返回我所有的喊叫声,但是我无法在JSON中访问所属的用户模型。
Route::get('api/shout', function() {
return Shout::with('users')->get();
});
Run Code Online (Sandbox Code Playgroud)
这只是返回此JSON,每次喊叫都没有用户对象:
[{"id":"1","user_id":"1","message":"A little test shout!","location":"K","created_at":"2013-05-23 19:51:44","updated_at":"2013-05-23 19:51:44"},{"id":"2","user_id":"1","message":"And here is an other shout that is a little bit longer...","location":"S","created_at":"2013-05-23 19:51:44","updated_at":"2013-05-23 19:51:44"}]
Run Code Online (Sandbox Code Playgroud) 在通过ajax获取之后,如何动态创建routes数组?
有没有办法在初始化后添加/推送新路由到路由器?
这不起作用:
new Vue({
el: '#app',
template: '<App/>',
data: {
content: []
},
created: function () {
this.$http.get('dummyjsondatafornow').then((response) => {
// this doesn't work when creating the VueRouter() outside the Vue instance, as in the docs.
// this.$router.options.routes.push({ path: '/about', component: About })
let routes = [
{ path: '/about', component: About }
]
// this doesn't work either
this.router = new VueRouter({
routes: routes
})
})
},
// router: router,
components: { App }
})
Run Code Online (Sandbox Code Playgroud) 我有一个这样的列表:
<ul>
<li><span class="date">2011 05 01</span><p>Text...</p></li>
<li><span class="date">2011 05 01</span><p>Text...</p></li>
<li><span class="date">2011 04 01</span><p>Text...</p></li>
<li><span class="date">2011 04 01</span><p>Text...</p></li>
<li><span class="date">2010 03 01</span><p>Text...</p></li>
<li><span class="date">2010 02 01</span><p>Text...</p></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我需要jQuery按年和月分组项目,如下所示:
<ul>
<li class="year">2011
<ul>
<li class="month>May
<ul>
<li class="item"><span class="date">2011 05 01</span><p>Text...</p></li>
<li class="item"><span class="date">2011 05 01</span><p>Text...</p></li>
</ul>
</li>
<li class="month>April
<ul>
<li class="item"><span class="date">2011 04 01</span><p>Text...</p></li>
<li class="item"><span class="date">2011 04 01</span><p>Text...</p></li>
</ul>
</li>
</ul>
</li>
<li class="year">2010
<ul>
<li class="month>March
<ul>
<li class="item"><span class="date">2011 03 01</span><p>Text...</p></li>
</ul>
</li>
<li class="month>February
<ul> …Run Code Online (Sandbox Code Playgroud) dom ×1
eloquent ×1
jquery ×1
laravel ×1
laravel-4 ×1
list ×1
orm ×1
vue-resource ×1
vue-router ×1
vue.js ×1