下面的脚本显示了使用的购物车ng-repeat.对于数组中的每个元素,它显示项目名称,其数量和小计(product.price * product.quantity).
计算重复元素总价的最简单方法是什么?
<table>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<tr ng-repeat="product in cart.products">
<td>{{product.name}}</td>
<td>{{product.quantity}}</td>
<td>{{product.price * product.quantity}} €</td>
</tr>
<tr>
<td></td>
<td>Total :</td>
<td></td> <!-- Here is the total value of my cart -->
</tr>
</table>
Run Code Online (Sandbox Code Playgroud) 我正在尝试滚动到 ScrollView 中的给定布局。我的 XML 基本上由实现各种relativelayout 的 ScrollView 组成,我想以编程方式滚动到给定的一个。
我的 Activity 的 onCreate 方法中有以下代码:
// Defining my view
sv = (ScrollView)findViewById(R.id.reward_scroll_view);
// Get Layout's id from intent
Bundle extras = getIntent().getExtras();
if (extras != null) {
idToScroll = extras.getInt("uiToScroll");
sv.post(new Runnable() {
public void run() {
// Scroll to the passed element
RelativeLayout layout = (RelativeLayout) findViewById(idToScroll);
sv.smoothScrollTo(0, layout.getTop());
}
});
}
Run Code Online (Sandbox Code Playgroud)
到给定锚点的“自动滚动”正在工作,但没有“平滑”效果,只是布局的原始滚动。我缺少什么?
我正在使用 angular 和这个插件来上传文件。它基本上开始处理文件上传,但我准备开始提交表单。
我试过这个:
HTML
<form>
<input type="file" ng-file-select="onFileSelect($files)">
<input type="submit" ng-click="sendMail()" value="send">
</form>
Run Code Online (Sandbox Code Playgroud)
JS
app.controller('mail', function ($scope, $http, $upload) {
$scope.onFileSelect = function($files) {
$scope.files = angular.copy($files);
console.log($scope.files); // Returns my object (size, type, name...)
}
$scope.sendMail = function() {
var file = myFile;
console.log(file); // Still returns my object
$scope.upload = $upload.upload({
url: 'server/mail.php',
data: {
// stuff
},
file: file, // Returns : Error: does not implement Blob
}).success(function(data, status, headers, config) {
console.log(data);
}); …Run Code Online (Sandbox Code Playgroud) 我正在尝试用ViewPager实现3个由3个片段(或3个布局)组成的幻灯片,我想知道我当前显示哪个幻灯片以显示适当的内容.简单来说,我想要幻灯片1上的内容1,幻灯片2上的内容2,依此类推.
这是我的Activity中的实际代码(来自android官方文档):
public class SliderActivity extends FragmentActivity {
private static final int NUM_PAGES = 3;
private ViewPager mPager;
private PagerAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slider);
// Instantiate a ViewPager and a PagerAdapter.
mPager = (ViewPager) findViewById(R.id.pager);
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
}
@Override
public void onBackPressed() {
if (mPager.getCurrentItem() == 0) {
// If the user is currently looking at the first step, allow the system to handle the
// Back button. This calls finish() on …Run Code Online (Sandbox Code Playgroud)