小编Saj*_*mad的帖子

如果在angularjs模板中有条件

我对AngularJs很新.我正在制作一个Q&A应用程序,我必须以表格的形式提出一些问题和答案.我有三种类型的问题,我必须以不同的方式呈现.每个问题都有一个分配的类型.如果question.type是"MCQ",则选项或其答案应使用HTML复选框呈现,如果问题类型为NUM,则应使用单选按钮呈现其答案.我试过这个并使用AngularJs模板中的条件.我的代码是

<table>
    <thead>
        <td>Questions</td>
        <td></td>
        <td>Hints</td>
    </thead>
    <tr data-ng-repeat="question in quizdata.questions">
        <td ng-if="question.type==MCQ">
            <li>{[{question.question_text}]}</li>
            <ol data-ng-repeat="answer in question.answers">
                <li>
                    <input type="checkbox">{[{answer.answer_text}]}</input> 
                </li>
            </ol>
        </td>

        <td ng-if="question.type==FIB">
            <ol data-ng-repeat="answer in question.answers">
                <li>
                    <input type="text"> </input>
                </li>
            </ol>
        </td>

        <td ng-if="question.type==NUM">
            <ol data-ng-repeat="answer in question.answers">
                <li>
                    <input type="radio">{[{answer.text}]}</input>
                </li>
            </ol>
        </td>

        <td></td>

        <td ng-if="quizdata.attempt_hint">
            {[{question.hint}]}
        </td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我试过这样的.但我认为如果条件没有执行.因为如果条件为false或true,它会渲染每种情况下的所有元素.我是否以正确的方式使用if条件?AngularJs模板中还有其他条件吗?帮助将受到高度赞赏.

javascript angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

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

配置angularjs模块发送补丁请求

我是AngularJs的新手.我正在尝试使用Angularjs向Django Tastypie API发送PATCH请求.我的代码是

var module = angular.module('myApp', []);

module.config(function ($httpProvider) {
});

function MyController($scope,$http)
{
$scope.patchCall=function(){
    $http({
    url: "/patchrequest/",
    data:data,
    method: "PATCH",
})
.success(function(data){
    console.log("SUCCESS");
    $scope.list = data.items;
}).error(function() {
    console.log("FAIL");
});
}
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用此代码发送请求时,我收到的错误是http.patch不是函数.告诉我如何配置ng-app和服务以使用AngularJs发送PATCH请求.我读取PATCH请求在$ resource中可用,所以我也厌倦了$ resource.但是找到相同的结果.请指导我如何从头开始配置应用程序以发送CRUD请求,特别是PATCH请求

javascript angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

11
推荐指数
1
解决办法
6755
查看次数

Google Chrome和Chrome不支持Discontigious Selection错误

我正在开发一个书签应用程序,我必须存储用户选择的关键字或单词或内容.我使用createRange()和addRange()javascript方法创建范围,然后由用户找出所选元素/内容.我为此编写的代码如下.

<head>
<script type="text/javascript">
    var storedSelections = [];

    function StoreSelection () {
        if (window.getSelection) {
            var currSelection = window.getSelection ();
            for (var i = 0; i < currSelection.rangeCount; i++) {
                storedSelections.push (currSelection.getRangeAt (i));
            }
            currSelection.removeAllRanges ();
        } else {
            alert ("Your browser does not support this example!");
        }
    }

    function ClearStoredSelections () {
        storedSelections.splice (0, storedSelections.length);
    }

    function ShowStoredSelections () {
        if (window.getSelection) {
            var currSelection = window.getSelection ();
            currSelection.removeAllRanges ();
            for (var i = 0; i < storedSelections.length; i++) …
Run Code Online (Sandbox Code Playgroud)

javascript firefox jquery google-chrome chromium

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

在Meteor.js模板中打印循环索引

我在meteorjs中有一个对象列表,我在meteorjs模板中迭代

{{#each objects}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)

在模板中我想打印循环迭代的次数.也就是说,如果对象列表的长度为100,我想在模板中打印1到100的数字.我怎样才能做到这一点?

javascript handlebars.js meteor

7
推荐指数
2
解决办法
6687
查看次数

在Laravel Php中打印服务器端的值

我是PHP和Laravel Framework的新手.我想在服务器端的Laravel中打印变量来检查它们包含的值.如何console.log在服务器上执行或打印变量值,以查看Laravel PHP中包含的变量值.

php laravel laravel-4 laravel-3

7
推荐指数
2
解决办法
9031
查看次数

错误:请安装PostgreSQL服务器开发包并重新运行configure

我正在尝试在我的ubuntu系统上为django框架安装Postgis.但每当我运行命令./configure它给我错误

 error: the PGXS Makefile /usr/lib/postgresql/9.3/lib/pgxs/src/makefiles/pgxs.mk cannot be found. Please install the PostgreSQL server development packages and re-run configure.
Run Code Online (Sandbox Code Playgroud)

我已经在我的系统上安装了postgres,并且还创建了用户.但我无法在我的系统上安装Postgis.我已经完成了我在互联网上找到的许多说明但未能安装它.

请告诉我这个错误的解决方案,以便我可以在ubuntu上安装Postgis.帮助将受到高度赞赏

django postgresql ubuntu postgis geodjango

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

Meteor Js,将图像存储到mongoDB

我想将文件输入浏览的图像存储到数据库中.我正在使用redactor插件使用此代码浏览图像

$('.editor').redactor({
    imageUpload:"/uploads"
});
Run Code Online (Sandbox Code Playgroud)

当我选择或浏览图像时使用此功能,我将使用流星HTTP方法直接将该图像发送到服务器

HTTP.methods({
    '/uploads': function(data) {
     console.log(data)
     Meteor.call("uploadImage",data)  
     return JSON.stringify({'Hello':"hello"});
    }
 });
Run Code Online (Sandbox Code Playgroud)

在这里,当我在做console.log数据时,我得到了图像的64位二进制代码.现在我想将这些数据保存到mongodb数据库.
我正在使用meteor-collection 2来定义字段及其类型.但我无法获得我必须使用哪种数据类型将图像存储到mongo db.
我正在尝试使用mongodb gridfs来存储图像.告诉我如何在mongodb中存储图像?感谢名单

javascript mongodb gridfs meteor meteorite

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

即使在成功创建对象之后,django modelformset_factory也能维持先前提交的数据

我在我的一个视图中使用django modelformset_factory.我正在使用javascript将新表单添加到Template中的formset.一切都运行正常,但我的问题是,当我尝试使用modelformset_factory创建一个新对象时,它会将所有对象显示为我之前创建的表单.或者简单地说,当我使用modelformset_factory表单创建一个新实例时,它会向我显示最后提交的表单.就像我extra = 0在初始化modelformset_factory时定义的那样,我从模板中添加了5个表单到formset并提交了这些表单.下次我将重新渲染模板以便为另一个用户创建calaendar时,它会向我显示我之前为之前用户提交的所有实例.意味着它将向我展示5个表格,其中包含我为之前用户提交的完整数据.

我的模型,Formset,Form和View如下.

class Calendar(models.Model):
    user = models.ForeignKey(User)
    name = models.CharField(max_length=200, null=True, blank=True)
    date = models.DateField(verbose_name=_('Date'))

    def __unicode__(self):
        return self.name

class UserCalendar(forms.ModelForm):
    date =forms.DateField(input_formats=['%d-%m-%Y', '%d-%m-%y'])
    class Meta:
        model = ProviderCalendar 
        exclude = ('user',)


class CalendarFormset(BaseModelFormSet):
    def __init__(self, *args, **kwargs):
        super(CalendarFormset, self).__init__(*args, **kwargs)
        for form in self.forms:
            form.empty_permitted = False

    def clean(self):
        return super(CalendarFormset, self).clean()

class CreateCalendar(LoginRequiredMixin,DetailView):
    model = Profile
    template_name = 'calendar_create.html'
    formset = modelformset_factory(Calendar,
      form=CalendarForm,
    formset=CalendarFormset,
    extra=0,
    )

def get(self, request, *args, **kwargs):
    self.object = …
Run Code Online (Sandbox Code Playgroud)

django django-models django-forms modelform django-views

2
推荐指数
1
解决办法
981
查看次数

Python正则表达式搜索不适用于包含冒号的字符串(:)

我有一个字符串,可以像"一些字符串{{key:value}}一样,字符串{{key:value}} {{key:value}}一些字符​​串"我想找到所有{{key:value}匹配给定字符串中的子字符串.对于这个我正在尝试的模式是:

string ="fdfd{{dsfdss:dssssasa}} fdsfdsfds"
pattern = re.compile("\\\\[a-z]\w+\:\[a-z]\w+\}}")
abc = re.search( pattern, string)
Run Code Online (Sandbox Code Playgroud)

我也试过这个

pattern = re.compile("\\\\[a-z]\w+:[a-zA-Z]\w+\}}")
abc = re.search( pattern, string)
Run Code Online (Sandbox Code Playgroud)

但每次它都返回无

建议我完成它的最佳方法.

python regex string

2
推荐指数
1
解决办法
729
查看次数

循环遍历一个对象数组并在laravel PHP中获取值

我正在开发一个QA应用程序,我需要根据需要动态地添加问题的多个答案.为此,我发送一个带有问题和答案的对象.

question={
    'question_text':'what is your name',
    'answers':[
            {'answer_text':'some answer','isCorrect':'1'},
            {'answer_text':'some answer','isCorrect':'1'},
            {'answer_text':'some answer'}    // answer may or may not have isCorrect key
        ]
    }
Run Code Online (Sandbox Code Playgroud)

在服务器端,我有两个表或迁移1用于问题,1用于回答.答案表有三个字段 question_id,answer_text' andisCorrect'.question_id是答案表中问题的外键.

存储我正在做的对象

$question_text=Input::get('question_text');
$answers=Input::get('answers');

$question=new Question;
$question->question_text=$question_text;
$question->save();


foreach($answers as $ans){ 
   $answer=new Answer;
   $answer->question_id=$question->id;
   $answer->answer_text=$ans->answer_text;
   if($answer->isCorrect){
        $answer->is_correct=$ans->isCorrect;
   }
   else{
        $answer->is_correct=0;
   }
   $answer->save();
}
Run Code Online (Sandbox Code Playgroud)

但是迭代时会出现错误

`production.ERROR: exception 'ErrorException' with message 'Trying to get property of non-object'`  
Run Code Online (Sandbox Code Playgroud)

我在这做什么错.我是第一次使用PHP.我试图像Javascript或Python方式迭代它.告诉我如何获取答案数组对象的值并存储它们.

php arrays laravel laravel-4 laravel-3

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

PHP中的非法字符串偏移错误

我将这些对象发送到服务器以获取记录并保存.但它给了我下面给出的错误

array(3) {
[0]=>
array(1) {
    ["answer"]=>
    string(218) "{"id":"19","question_id":"10","answer_text":"Please note that we also maintain you:",  
"iscorrect":"1",
"created_at":"2014-06-07 07:52:12",  
"updated_at":"2014-06-07 07:52:12"}"
  }
  [1]=>
 array(1) {
   ["answer"]=>
    string(218) "{"id":"20","question_id":"10","answer_text":"Please note that we also maintain the following pages and support forums to help you:",  
"iscorrect":"1",
"created_at":"2014-06-07 07:52:13",  
"updated_at":"2014-06-07 07:52:13"}"
 }
[2]=>
array(1) {
  ["answer"]=>
  string(218) "{"id":"21","question_id":"10",  
  "answer_text":"Please note that we also maintain the following pages and support forums to help you:","iscorrect":"0","created_at":"2014-06-07 07:52:13","updated_at":"2014-06-07 07:52:13"}"
}
}

{"error":{"type":"ErrorException","message":"Illegal string offset     'id'","file":"\/home\/learnomatics\/laravel\/mobillz_mlmalp\/app\/controllers\/QuizController.php","line":379}}
Run Code Online (Sandbox Code Playgroud)

我试图得到像这样的价值观

$answers=Input::get('answers');
var_dump($answers);
foreach …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-4

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

当在div体中工作时,ng-show不在表中工作

我在div元素中有两个表.我想在模板加载时隐藏两个表.并希望根据条件显示它们.为此,我在div中创建了两个表,并在两个表中放置了ng-show属性.但是表格是可见的而不是隐藏的 我的代码是

如果我在div中放置相同的ng-show属性它会被隐藏,但是表格不会被隐藏.告诉我这里我做错了什么?帮助将是可观的

<table ng-modal="deferredquiz" ng-show="showdeferredquizz" ng-true-value="true" ng-false-value="false" class="ng-hide">
    <tr>dddddddddddddddddddddd</tr>
        <tr data-ng-repeat="question in quizdata.questions">
            <td ng-switch="question.question_type">


                </td>               
        </tr>
        <tr>

        </tr>
    </table>

    <table ng-show="showimmediatequiz" ng-true-value="yes" ng-false-value="no">
        <tr>

        </tr>
        <tr>
            <td><button ng-click="submitDeferredQuiz()">Submit</button></td>
        </tr>
    </table>
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

0
推荐指数
1
解决办法
2346
查看次数