我最近使用bootstrap实现了一个小缩略图库,我想使用模式能够以更大的尺寸弹出图像。
到目前为止,我已经触发了模态,但我不知道如何为单击的图像显示该特定值。
这是我的缩略图生成:
<div class="row">
{{#each value in images}}
<div class="col-md-4">
<a class="thumbnail" data-toggle="modal" data-target="#myModal">
<img src="data:{{unbound value.mimeType}};base64,{{unbound value.image}}">
</a>
</div>
{{/each}}
</div>
这里是我的模态(非常基本的):
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">title of my image</h4>
</div>
<div class="modal-body">
Images here
</div>
</div>
</div>
</div>
是否可以使用车把检索一个特定值以显示在我的模态中?
我会知道如何在js中做到这一点,但是使用ember和把手有点困难。
[edit]我页面查询的控制器:
App.EnquiryController = Ember.ObjectController.extend({
isUpdating: false,
actions: {
showUpdateForm: function() {
this.setProperties({ isUpdating: true });
},
customerUpdate: function() {
this.setProperties({ isUpdating: false});
var data = this.get('model');
var obj = {
customerName: data.enquiry.customerName,
customerEmail: data.enquiry.customerEmail,
customerPhone: data.enquiry.customerPhone
};
console.log(obj);
Ember.$
.post(host + '/enquiry/' + data.enquiry.id, obj, function(data) {
console.log('DEBUG: Updating customer data OK');
});
},
cancelCustomerUpdate: function() {
this.setProperties({isUpdating: false});
},
tradeInUpdate: function() {
var data = this.get('model');
var obj = {
mileage: data.tradeIn.mileage,
valuationPrice: data.tradeIn.valuationPrice
};
console.log(data);
Ember.$
.post(host + '/enquiry/' + data.enquiry.id + '/tradeIn', obj, function(data) {
console.log('DEBUG: Update TradeIn OK')
})
},
summaryUpdate: function() {
var data = this.get('model');
var obj = {
deposit: data.totals.deposit,
discount: data.totals.discount
};
Ember.$
.post(host + '/enquiry/' + data.enquiry.id, obj, function(data) {
console.log('DEBUG: Update Summary OK');
});
console.log(obj);
}
}
});
我有很多数据显示在那里使用选项卡bootstrap来隐藏和显示它。
[edit2]错误:
Uncaught TypeError: Object function () {
if (!wasApplied) {
Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
var m = met...<omitted>...t'
[edit3]我得到了良好的图像链接但我无法从视图中设置控制器变量..
var ClientView = Em.View.extend({
actions: {
selectItem : function(item) {
console.log(item.uri);
App.EnquiryController.set("imageSrc", item.uri);
}
}
});
{{#view ClientView}}
<div class="row">
{{#each value in images}}
<div class="col-md-4">
<a class="thumbnail" data-toggle="modal" data-target="#myModal" {{action "selectItem" this.value target="view"}}>
<img src="data:{{unbound value.mimeType}};base64,{{unbound value.image}}">
</a>
</div>
{{/each}}
</div>
{{/view}}
在我的控制器中:
App.EnquiryController = Ember.ObjectController.extend({
imageSrc: null
});
答案 0 :(得分:0)
我在其他情况下遇到了这个问题。所以我做的是
{{#view ClientView}}
<div class="row">
{{#each value in images}}
<div class="col-md-4">
<a class="thumbnail" data-toggle="modal" data-target="#myModal" {{#action selectItem this target="view">
<img src="data:{{unbound value.mimeType}};base64,{{unbound value.image}}">
</a>
</div>
{{/each}}
</div>
{{/view}}
然后在视图中例如:
var ClientView = Em.View.extend({
actions: {
selectItem : function(item){
ClientController.set("imageSrc", item.src);
}
}
})
在模态中我把它:
<img {{bindAttr src="ClientController.imageSrc"}}>
我希望这可以帮到你