6
我開發骨幹的應用程序,這使得跨域寧靜的請求。在請求中的嵌套數據結構是必需的,在嫋嫋的請求我有一個結構:骨幹型號:嵌套數據結構
{
"site_id": 1,
"post": {
"site_id": 1,
"provider_id": 1,
"provider_post_id":1,
"created_ts": "12.12.12",
"post": {
"header": "text",
"caption": "text",
"image": "http://...jpg"
}
}
}
在我還沒有嵌套結構,這是很舒服的模式,因爲我在view
(DOM使用image
示範田元素創建)。
什麼嵌套數據從骨幹應用程序發送到服務器的正確方法是什麼?
型號:
var WraperModel = Backbone.Model.extend({
url: 'http://mydomain/core/api/v1/bookmarklet_post/? callback=?',
defaults: {
site_id: 1, // shouldn't be hardcoded
type:"type", site_id:2, provider_id: 2, provider_post_id: 2, created_ts:2,
header : '',
caption: '',
image: ''
},
});
的視圖的一部分,它使用image
模型屬性:
drawItem: function (model) {
var inst = new ImageView({model: model, tagName: 'li', className:'images-item'}).render();
this.imagesWrapper.append(inst.el);
},
getImages: function() {
var images = doc.getElementsByTagName('img'),
view = this;
_.each(images, function (image) {
image.offsetHeight > 75
&& image.offsetWidth > 75 &&
view.collection.add({image: image.src});
});
},
另一視圖,其將數據發送到服務器的一部分。
sendTo: function(){
var that = this,
data = {saving: true};
$('#add-header').val() && (data.header = $('#add-header').val());
$('#add-description').val() && (data.caption = $('#add-description').val());
this.model.set(data);
this.model.save();
}
很好的解決!在這個時候,我在服務器端處理了數據。 – I159 2012-03-15 10:47:15