Kra*_*ama 5 jquery twitter-bootstrap ember.js ember-data bootstrap-modal
我使用ember js和bootstrap我有一个使用bootstrap的表
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Request Id</th>
<th>Applied By</th>
<th>Leave Type</th>
<th>Leave From</th>
<th>Leave To</th>
<th>Days</th>
<th>Status</th>
<th>Applied date</th>
<th>Applied/Declined date</th>
</tr>
</thead>
<tbody data-link="row" class="rowlink">
{{#each model.pending}}
<tr id="ptable" data-toggle="modal" data-target="#pendingrequestsmodal" style="cursor: pointer">
<td id="eid">{{id}}</td>
<td>{{employee_id}}</td>
<td>{{type_id}}</td>
<td>{{from_date}}</td>
<td>{{to_date}}</td>
<td>{{days}}</td>
<td>{{status}}</td>
<td>{{to_date}}</td>
<td>{{to_date}}</td>
</tr>
{{/each}}
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
现在,当有人点击表格行时,我正在显示bootstrap模式以进行确认
<div id="pendingrequestsmodal" class="modal fade">
<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">Confirmation</h4>
</div>
<div class="modal-body">
<button type="button" class="btn btn-default" data-dismiss="modal">Decline</button>
<button type="button" class="btn btn-primary" {{action "pendingAction" target="controller" }}>Approve</button>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望这些点击的行详细信息在ember中,以便我可以在服务器上处理它
App.ApprovalrequestsController = Ember.ObjectController.extend({
actions: {
pendingAction: function () {
//here i want to get the details of clicked row
//this.transitionToRoute("approvalrequests", rdata);
}
}
});
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我如何在ember中获取点击的行详细信息
有两个问题需要解决,在事件上传递选定的对象/模型(例如,单击批准按钮时)能够使用复杂的模板作为模式的内容(例如,当单击模式可能包含的行时)来自主从关系的表单或数据)。
一种方法是每次在一行上进行选择时刷新模式的内容。单击行时可以处理选择,并且可以通过为其分配模板并将其呈现绑定到属性来实现模式(可能丰富/复杂)内容的刷新。
为简单起见,以下示例使用partial模板来保存模式的内容和具有一个属性 ( name) 作为模型的简单对象。
http://emberjs.jsbin.com/gecehotu/1/edit
乙肝病毒
<script type="text/x-handlebars" data-template-name="index">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>color</th>
</tr>
</thead>
<tbody data-link="row" class="rowlink">
{{#each model}}
<tr id="ptable" data-toggle="modal" data-target="#pendingrequestsmodal" style="cursor: pointer" {{action "selectColor" this target="view"}}>
<td>{{name}}</td>
</tr>
{{/each}}
</tbody>
</table>
{{#if selectedColor}}
{{partial "popup"}}
{{/if}}
</script>
<script type="text/x-handlebars" data-template-name="_popup">
<div id="pendingrequestsmodal" class="modal fade">
<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">Confirmation</h4>
<br/>
{{selectedColor.name}}
</div>
<div class="modal-body">
<button type="button" class="btn btn-default" data-dismiss="modal">Decline</button>
<button type="button" class="btn btn-primary" {{action "pendingAction" selectedColor target="controller" }}>Approve</button>
</div>
</div>
</div>
</script>
Run Code Online (Sandbox Code Playgroud)
js
App = Ember.Application.create();
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return [{name:'red'}, {name:'yellow'}, {name:'blue'}];
}
});
App.IndexController = Ember.ArrayController.extend({
selectedColor:null,
actions:{
pendingAction:function(color){alert("the color is:"+color.name);}
}
});
App.IndexView = Ember.View.extend({
actions:{
selectColor:function(color){
this.controller.set("selectedColor",color);
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10270 次 |
| 最近记录: |