小编man*_*nza的帖子

将图像文件附加到表单数据 - Cordova/Angular

我在我当前的项目中使用Anuglar,Ionic和Cordova,我正在尝试将包含图像文件的FormData发布到我的服务器.现在我正在使用cordova相机插件将文件路径返回到设备上的图像(例如:file:// path/to/img).一旦我有了文件路径,我想使用images文件路径将图像文件附加到FormData对象.这是我现在的代码.

var fd = new FormData();

fd.append('attachment', file);
fd.append('uuid', uuid);
fd.append('userRoleId', userRole);
Run Code Online (Sandbox Code Playgroud)

上面的代码在附加从文件中获取的文件时起作用,<input type='file'>但在给定设备上的文件路径时不起作用.

基本上FormData现在显示如下:

------WebKitFormBoundaryasdf
Content-Disposition: form-data; name="attachment"; 

file://path/to/img
Run Code Online (Sandbox Code Playgroud)

我希望它看起来像这样

------WebKitFormBoundaryasdf
Content-Disposition: form-data; name="attachment"; filename="jesus-quintana.jpg"
Content-Type: image/jpeg
Run Code Online (Sandbox Code Playgroud)

我找到了许多不同的方法来使用cordova FileTransfer上传图像,并将图像转换为base64然后上传它.但我找不到任何简单的方法来通过使用路径并在表单中发布它来抓取文件.我对File Api不是很熟悉,所以任何帮助都会受到赞赏

javascript android angularjs cordova ionic-framework

20
推荐指数
2
解决办法
2万
查看次数

ng-click在离子标题按钮中不起作用

我试图在标题栏的右侧添加一个按钮,按钮显示,但ng-click不会被触发,如果我在离子内容中移动按钮,它开始工作,只是不在标题中工作.

HTML:

<ion-view>
    <ion-nav-bar class="bar-stable nav-title-slide-ios7" >
      <ion-nav-back-button class="button-icon icon  ion-ios7-arrow-back">
      </ion-nav-back-button>
    </ion-nav-bar>
    <ion-header-bar>
        <h1 class="title">Trips</h1>
        <div class="buttons pull-right"><button class="button button-icon icon ion-plus" ng-click="createTrip()"></button></div>
    </ion-header-bar>

    <ion-content>

    </ion-content>
</ion-view>
Run Code Online (Sandbox Code Playgroud)

JS:

.controller('TripCtrl', function($scope, $location, $localStorage){
    console.log('inside TripCtrl');

    $scope.$storage = $localStorage;

    var random1 = {
        name : 'random name 1',
        text : 'random text 1'
    }

    var random2 = {
        name : 'random name 2',
        text : 'random text 2'
    }

    $scope.trips = [];
    $scope.trips.push(random1);
    $scope.trips.push(random2);


    $scope.createTrip = function(){
        console.log('clicked create new');
        $location.path('/createTrip'); …
Run Code Online (Sandbox Code Playgroud)

angularjs ionic-framework

7
推荐指数
1
解决办法
2188
查看次数

使用Restangular取消对服务器的GET请求

我创建了一个UserService,如下所示:

angular.module('nrApp').factory('userService', ['Restangular', 'UserModel', 'DSCacheFactory', function (Restangular, UserModel, DSCacheFactory) {
    // Create a new cache called "profileCache"
    var userCache = DSCacheFactory('userCache', {
        maxAge: 3600000,
        deleteOnExpire: 'aggressive',
        storageMode: 'localStorage', // This cache will sync itself with `localStorage`.
        onExpire: function (key, value) {
            Restangular.oneUrl('users', key).get().then(function(data) {
                userCache.put(key, data);
            });
        }
    });

    Restangular.extendModel('users', function(obj) {
        return UserModel.mixInto(obj);
    });

    Restangular.addRequestInterceptor(function(element, operation, what, url) {
        if(operation === 'get') {
            debugger;
            //Check the cache to see if the resource is already cached
            var data = userCache.get(url); …
Run Code Online (Sandbox Code Playgroud)

caching angularjs restangular angular-cache

6
推荐指数
1
解决办法
2471
查看次数

我应该声明JavaScript变量然后立即初始化吗?

我是JavaScript新手,我想知道如果声明变量然后在声明后立即初始化是最佳实践.例如:

var x = 5 ;
var y = 6 ;
Run Code Online (Sandbox Code Playgroud)

代替:

var x , y ;

x = 5;
y = 6 ; 
Run Code Online (Sandbox Code Playgroud)

javascript

5
推荐指数
1
解决办法
665
查看次数

基于generator-gulp-angular在Ionic项目上配置Live Reload

我有一个Ionic 1.3.1项目,其架构基于旧的但是金色的generator-gulp-angular,我想Live Reload在设备(Android)上启用它.

我的gulp配置路径如下所示:

exports.paths = {
  src: 'src',
  dist: 'www',
  tmp: '.tmp',
  e2e: 'e2e'
};
Run Code Online (Sandbox Code Playgroud)

这意味着要在我使用的浏览器中运行项目,gulp serve并在我使用的Android设备中运行gulp build && ionic run android.

我不能使用ionic run android --livereload 此处doc中描述的命令,因为它同步www文件夹(在a之后gulp build)我有缩小文件而不是源文件.

所以我想以某种方式混淆这两个命令gulp serve,ionic run android --livereload但真诚地我不知道如何实现这一点.

android angularjs gulp ionic-framework gulp-livereload

5
推荐指数
1
解决办法
410
查看次数

Object仅在IE8上不支持此属性或方法

此代码在Chrome,FF,Safari,IE9上运行,但在IE8上我收到此错误:

消息:对象不支持此属性或方法行:80字符:7代码:0

这就是它停止的代码:(第80行是"return ["但开发人员工具调试器突出显示下面的所有代码)

return [
    {
        title:'Edit',
        customClass:'actionEdit',
        action:{
            type:'getLink',
            url:'/admin/products/edit/'+data.id()+''
        }
    },
    {
        title:'Attaches',
        customClass:'actionAttaches',
        action:{
            type:'getLink',
            url:'/admin/attaches/index/product/'+data.id()+''
        }
    },
    {
        title:'Delete',
        customClass:'actionDelete',
        action:{
            type:'postLink',
            url:'/admin/products/delete/'+data.id()+'',
            confirm:'Are you sure you want to delete %s?',
            arg:$('#ProductAdminIndexList #'+data.id()+' .productId').text().trim()
        }
    }
];
Run Code Online (Sandbox Code Playgroud)

我发现其他类似的情况,但我不知道为什么会发生,如何解决这个问题.

javascript internet-explorer-8

4
推荐指数
1
解决办法
7132
查看次数

使用图表师在条形图中对齐图例

我正在尝试使用图表为条形图创建图例,我已使用图表插件作为图例,但我无法将其与图表底部对齐,任何人都可以提供有关如何自定义 . (我曾尝试在 css 中使用它,但无法反映我的更改。)

HTML :

<chartist class="ct-chart ct-major-twelfth"
    chartist-chart-type="Bar"
    chartist-data="chartData"
    chartist-chart-options="chartOptions">
</chartist>
Run Code Online (Sandbox Code Playgroud)

JS:

chartData = {
    labels: [],
    series: [[]]
};

chartOptions= {
    plugins: [
        Chartist.plugins.legend()
    ]
};
Run Code Online (Sandbox Code Playgroud)

传奇.JS:

 $ct-series-colors: (#d70206, #F05B4F, #F4C63D, #453D3F) !default;

.ct-legend {
    position: relative;
    z-index: 10;

    li {
        position: relative;
        padding-left: 23px;
        margin-bottom: 3px;
    }

    li:before {
        width: 12px;
        height: 12px;
        position: absolute;
        left: 0;
        content: '';
        border: 3px solid transparent;
        border-radius: 2px;
    }

    li.inactive:before {
        background: transparent;
    }

    &.ct-legend-inside {
        position: absolute; …
Run Code Online (Sandbox Code Playgroud)

html javascript legend angularjs chartist.js

3
推荐指数
1
解决办法
4975
查看次数