我們有灰燼的對象,這是我們想從一個AJAX調用數據來填充:使用來自AJAX調用(XHR請求)的JSON數據填充ember對象的最佳方法是什麼?
window.App = Ember.Application.create(
{ rootElement: '#container' }
);
App.WindowDetail = Ember.Object.create({
ID: "",
Title: "",
InteriorFinishesDescription: ""
});
目前,我們正在通過Ajax調用以這種方式獲得的JSON數據:
$(window).load(function() {
//Call the page method
$.ajax({
type: "POST",
url: "TestController.aspx",
//contentType: "application/json; charset=utf-8",
data: "asaw",
dataType: "json",
success: function (r) {
App.WindowDetail.InteriorFinishesDescription = r.InteriorFinishesDescription;
alert(App.WindowDetail.InteriorFinishesDescription);
}
});
});
在這個示例中,JSON數據可以很好地再現 - 「App.WindowDetail.InteriorFinishesDescription」被填充。
問題是模板沒有被填充。而且,我不認爲這是使用Ember JS時返回JSON數據的正確方法。
這裏是什麼樣的車把模板看起來像一個示例:
<script type="text/x-handlebars">
<div class="two columns">
{{App.WindowDetail.InteriorFinishesDescription}}
</div>
</script>
我認爲我已經找到了一個方向和可能的答案來解決我自己的問題:Ember Resource,https://github.com/staugaard/ember-resource。感謝Dan Gebhardt(http://stackoverflow.com/users/664735/dan-gebhardt)對他的回覆(http://stackoverflow.com/questions/9020614/how-to-bind-content-with- json-in-ember-js/9022905#9022905) – elcorando 2012-02-02 19:52:04