0
我開始knockoutjs,但我想知道我怎麼能做到這一點。我想添加src屬性哪一個將包含靜態和動態內容。請查看底部knockoutjs viewmodel綁定與阿賈克斯和計算
var viewModel = {
title : ko.observable("title"),
description : ko.observable("description"),
poster : ko.observable("poster"),
imdb : ko.observable("imdb")
movie : ko.computed(function(){
return 'https://www.youtube.com/embed?listType=search&list='+this.title()+'&autoplay=1&origin=http://filmmovies.in&fs=0&modestbranding=1&rel=0&loop=1&color=white&controls=0&mode=opaque'
})
};
$.post('/movies/index').then(function(data){
ko.applyBindings({movies: data});
});
======================================== 請求響應
[
{"title":"Iron Man","description":"asdf kasdf <H1>hsdifaf</H1>","poster":"http://www.google.com","imdb":"[email protected]","createdAt":"2017-05-02T07:42:28.864Z","updatedAt":"2017-05-02T07:42:28.864Z","id":10},
{"title":"Iron Man","description":"asdf kasdf <H1>hsdifaf</H1>","poster":"http://www.google.com","imdb":"[email protected]","createdAt":"2017-05-02T06:53:51.984Z","updatedAt":"2017-05-02T06:53:51.984Z","id":1},
{"title":"Iron Man","description":"asdf kasdf <H1>hsdifaf</H1>","poster":"http://www.google.com","imdb":"[email protected]","createdAt":"2017-05-02T06:55:20.245Z","updatedAt":"2017-05-02T06:55:20.245Z","id":3},
{"title":"Iron Man","description":"asdf kasdf <H1>hsdifaf</H1>","poster":"http://www.google.com","imdb":"[email protected]","createdAt":"2017-05-02T07:12:45.620Z","updatedAt":"2017-05-02T07:12:45.620Z","id":4}
]
是來自請求的數據是數組嗎? –
是來自請求的數據是一個數組,但是數組的每個元素都是json對象 –
您使用共享的代碼面臨什麼問題?你想通過這個 - http://stackoverflow.com/help/how-to-ask – gkb