我对这个大多数人来说都是非常新的,所以我的歉意是,我的代码大部分都是从这个论坛借用和欺骗的,我正在学习。AngularJS中的可编辑表格单元格
目前我正试图复制一个加热器计时系统,每天有6个开关可以改变温度。
我已经通过我的控制器加载了一些示例数据,并使用ng-repeat在表格中显示,但它并不理想,但暂时工作并将按我的要求做。
我的数据显示是静态的,没有格式或排序,只能编辑。
我现在卡在下一个阶段,表格中的每个单元格都是可编辑的。我已经阅读了大量的帖子和信息(主要在行和使用ng-grid和其他插件),我希望有人可以指出我在正确的方向请如何继续我的当前代码如何id每个单击并点击弹出一个模式,这将允许输入组成每个单元格,小时,分钟和温度的三个元素。
请不要期望自定义代码或高级课程,我知道我的工作是非常基础的,但是如果有人能指向我正确的方向或一些有用的链接,将不胜感激。
我第一次在这里发帖,希望我提供的信息足够清楚。
p.s.我现在要睡觉(英国时间晚上11点30分),今天上午7点以后(大部分周末)我都要睡觉,因此我需要让自己远离屏幕。
function rowController($scope) {
$scope.sw1 = [{
hours: '01',
minutes: '05',
temp: '32'
}, {
hours: '02',
minutes: '05',
temp: '20'
}, {
hours: '03',
minutes: '05',
temp: '13'
}, {
hours: '04',
minutes: '05',
temp: '23'
}, {
hours: '05',
minutes: '05',
temp: '12'
}, {
hours: '06',
minutes: '05',
temp: '02'
}, {
hours: '07',
minutes: '05',
temp: '02'
}, ];
$scope.sw2 = [{
hours: '01',
minutes: '10',
temp: '32'
}, {
hours: '02',
minutes: '10',
temp: '20'
}, {
hours: '03',
minutes: '10',
temp: '13'
}, {
hours: '04',
minutes: '10',
temp: '23'
}, {
hours: '05',
minutes: '10',
temp: '12'
}, {
hours: '06',
minutes: '10',
temp: '02'
}, {
hours: '07',
minutes: '10',
temp: '02'
}, ];
$scope.sw3 = [{
hours: '01',
minutes: '15',
temp: '32'
}, {
hours: '02',
minutes: '15',
temp: '20'
}, {
hours: '03',
minutes: '15',
temp: '13'
}, {
hours: '04',
minutes: '15',
temp: '23'
}, {
hours: '05',
minutes: '15',
temp: '12'
}, {
hours: '06',
minutes: '15',
temp: '02'
}, {
hours: '07',
minutes: '15',
temp: '02'
}, ];
$scope.sw4 = [{
hours: '01',
minutes: '20',
temp: '32'
}, {
hours: '02',
minutes: '20',
temp: '20'
}, {
hours: '03',
minutes: '20',
temp: '13'
}, {
hours: '04',
minutes: '20',
temp: '23'
}, {
hours: '05',
minutes: '20',
temp: '12'
}, {
hours: '06',
minutes: '20',
temp: '02'
}, {
hours: '07',
minutes: '20',
temp: '02'
}, ];
$scope.sw5 = [{
hours: '01',
minutes: '25',
temp: '32'
}, {
hours: '02',
minutes: '25',
temp: '20'
}, {
hours: '03',
minutes: '25',
temp: '13'
}, {
hours: '04',
minutes: '25',
temp: '23'
}, {
hours: '05',
minutes: '25',
temp: '12'
}, {
hours: '06',
minutes: '25',
temp: '02'
}, {
hours: '07',
minutes: '25',
temp: '02'
}, ];
$scope.sw6 = [{
hours: '01',
minutes: '30',
temp: '32'
}, {
hours: '02',
minutes: '30',
temp: '20'
}, {
hours: '03',
minutes: '30',
temp: '13'
}, {
hours: '04',
minutes: '30',
temp: '23'
}, {
hours: '05',
minutes: '30',
temp: '12'
}, {
hours: '06',
minutes: '30',
temp: '02'
}, {
hours: '07',
minutes: '30',
temp: '02'
}, ];
}
th, td {
text-align: center;
}
col {
min-width:95px;
max-width:95px;
}
.table {
width:auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
<div ng-app="" ng-controller="rowController">
<div class="table-responsive col-xs-12">
<table class="table table-bordered table-striped">
<colgroup>
<col span="1" />
<col span="1" />
<col span="1" />
<col span="1" />
<col span="1" />
<col span="1" />
<col span="1" />
</colgroup>
<thead>
<tr class="info">
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
<th>Sunday</th>
</tr>
</thead>
<tbody>
<tr>
<td ng-repeat="x in sw1">{{ x.hours + ':' + x.minutes + ' ' + x.temp + '° c' }}</td>
</tr>
<tr>
<td ng-repeat="x in sw2">{{ x.hours + ':' + x.minutes + ' ' + x.temp + '° c' }}</td>
</tr>
<tr>
<td ng-repeat="x in sw3">{{ x.hours + ':' + x.minutes + ' ' + x.temp + '° c' }}</td>
</tr>
<tr>
<td ng-repeat="x in sw4">{{ x.hours + ':' + x.minutes + ' ' + x.temp + '° c' }}</td>
</tr>
<tr>
<td ng-repeat="x in sw5">{{ x.hours + ':' + x.minutes + ' ' + x.temp + '° c' }}</td>
</tr>
<tr>
<td ng-repeat="x in sw6">{{ x.hours + ':' + x.minutes + ' ' + x.temp + '° c' }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<script src="rowController.js"></script>
下面就来
而不是仅仅渲染数据,使用''标签的内' NG-repeat's。然后,如果你想要适当的时间输入,你可以使用一些timepicker库:http://mgcrea.github。io/angular-strap/##时间选择器 – floribon 2015-02-09 23:34:20
谢谢floribon对于时间选择器的快速反应和建议,我为我的代码玩过时间选取器,并遇到一些问题,所以想出了一个非常基本的列表选择器,我希望呼叫。如果我在线上使用输入标签,我是否需要获取单元ID来调用我的数据(道歉我的措辞是如此基本)。我已经看到了很多修改行的例子,但是没有一个在单元级别工作,也没有我通过数据获取的方式,让自己迷失了方向。 – 2015-02-09 23:44:51
对不起,我不明白你的意思是“我需要获取手机号码才能拨打我的数据”。但是你可能不需要,所有的数据都来自ng-repeat,如果你想处理用户的改变,你可以添加'ng-change =“onDataChange($ index,model)”'来知道你编辑了哪个单元例如。 – floribon 2015-02-09 23:56:43