小编ahm*_*111的帖子

Backbone以正确的方式获取回调

我的Backbone应用程序有一个名为schedule的视图,我对成功和错误调用正确函数的区别有点困惑,我尝试了下面列出的两个可能但我没有什么区别和什么是正确的从外部视图中放置的路由器调用函数的方法:

第一种方式:

        require([
            'app/collections/schedule',
            'app/views/schedule'
        ], function(ScheduleCollection, ScheduleView) {

           var scheduleCollection = new ScheduleCollection(),
            scheduleView = new ScheduleView({
                model: scheduleCollection
            });

            scheduleCollection.fetch({
                reset: true,                
                success: function(){
                    scheduleView.successHandler();
                },
                error: function(){
                    scheduleView.errorHandler()
                }
            });
        });
Run Code Online (Sandbox Code Playgroud)

第二种方式

        require([
            'app/collections/schedule',
            'app/views/schedule'
        ], function(ScheduleCollection, ScheduleView) {

           var scheduleCollection = new ScheduleCollection(),
            scheduleView = new ScheduleView({
                model: scheduleCollection
            });

            scheduleCollection.fetch({
                reset: true,                
                success: scheduleView.successHandler(),
                error: scheduleView.errorHandler()                  
            });
        });
Run Code Online (Sandbox Code Playgroud)

在scheduleView中

successHandler: function(){
   console.log('success');
}


erroHandler: function(){
   console.log('error');
}
Run Code Online (Sandbox Code Playgroud)

javascript amd backbone.js

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

REST API登录方法

我们正在构建需要所有页面的登录信息的系统.该应用程序被设计为使用codeigniter作为Phil Sturgeon库的Restful应用程序.此库仅使用API​​密钥通过HTTPS连接的每个请求发送api调用来授权api调用.

即使它使用2路认证或仅使用API​​密钥.我正在寻找一段时间是以下场景:

  • 用户首次请求该应用程序(例如:https://www.xyz.com),然后将其重定向到登录页面以检查凭据
  • 用户输入usernam /密码并通过https发送
  • 服务器检查信息是否有效,然后:

    • API KEY应由服务器提供给客户端,作为此用户名标识的资源(这是问题??? !!!)

    • 如何以安全的方式将API密钥发送到客户端?

      • 1)我可以使用会话cookie并在cookie中恢复API KEY,然后在每个即将到来的请求中使用此API KEY(这是暴力的其余的无状态,我不确定它是否足够安全).
      • 2)实际上我不知道其他选择:)如果你能提供帮助,轮到你了

如果你能给出一个例子,那将是一个很大的帮助,因为我找到并阅读了很多文章

:)

authentication rest codeigniter

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

然后换行元素在其中附加另一个元素

看看这段代码

<div class="preview">
    <img src="link" alt="" class="overlay" />
</div>
Run Code Online (Sandbox Code Playgroud)

我需要做的是将内部div调用"overlay"包装,然后添加另一个名为"overlay2"的div,如下所示

<div class="preview">
    <div class="overlay">
        <img src="link" alt="" class="overlay" />
        <div class="overlay2"></div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我试图使用.wrap和追加但我不知道如何使用一个命令

jquery

5
推荐指数
2
解决办法
6252
查看次数

创建视图实例时,Backbone.js不是构造函数错误

我是backbone.js的新用户,并测试我如何使用它,最近几天我测试了如何使用route来通过集合更改视图数据.

在目前的情况下,我遇到了一个问题,当我试图在router.js中创建一个ScheduleView实例时,控制台会记录以下错误消息:

TypeError: ScheduleView is not a constructor
Run Code Online (Sandbox Code Playgroud)

下面是调度模块{view,collection,model} + router.js三页的代码

路由器

// Filename: router.js
define([
    'jquery',    
    'underscore',
    'backbone',
    'app/views/schedule',
    'app/collections/schedule'
], function($, _, Backbone, ScheduleView, ScheduleCollection) {
    var AppRouter = Backbone.Router.extend({
        routes: {
            // Define some URL routes
            'schedule': 'scheduleRoute',
            // Default
            '*actions': 'defaultRoute'
        },
        scheduleRoute: function() {
            // Create a new instance of the collection
            // You need to set the url in the collection as well to hit the server
            var schedulecollection = new ScheduleCollection();
            // Pass …
Run Code Online (Sandbox Code Playgroud)

javascript backbone.js

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

Codeigniter表单验证对于JSON数据始终为false

我正在使用codeigniter构建自己的REST Web服务,该应用程序具有名为“ calls ” 的资源,并且可以通过POST方法访问它,

调用 ”函数通过使用以下内容类型Curl调用通过json对象接收四个参数[id,manager,department,level]作为json对象:application / json

然后我正在使用codeigniter form_validation()库来验证请求,然后在form_validation()上没有错误的情况下返回响应数组

问题是,尽管我可以按预期输出接收到的值,但form_validation()始终返回FALSE。

以下是通话功能代码

function calls_post() {

$this->load->model('api/central');
$this->load->library('form_validation');

//validation rules
$this->form_validation->set_error_delimiters('', '');
$this->form_validation->set_rules('id', 'id', 'required|numeric');
$this->form_validation->set_rules('manager', 'manager', 'required|numeric');
$this->form_validation->set_rules('department', 'department', 'required');
$this->form_validation->set_rules('level', 'level', 'required|numeric');


if ($this->form_validation->run() === FALSE) {

    $employeeId = $this->form_validation->error('id') ? $this->form_validation->error('id') : $this->post('id');
    $manager = $this->form_validation->error('manager') ? $this->form_validation->error('manager') : $this->post('manager');
    $department = $this->form_validation->error('department') ? $this->form_validation->error('department') : $this->post('department');
    $level = $this->form_validation->error('level') ? $this->form_validation->error('level') : $this->post('level');

    $response = …
Run Code Online (Sandbox Code Playgroud)

rest codeigniter

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

从列表构建数组

我怎么能建立一个以下字符串数组:

$scope = "calls:full,departments:full,employees:full,companies:full,stages:full,accounts:full,resources:full,products:full,reports:full";
Run Code Online (Sandbox Code Playgroud)

像这样代表它:

$scope = array(
    'calls' => full,
    'departments' => full,
    'employees' => full,
    .... and so on >>
);
Run Code Online (Sandbox Code Playgroud)

php arrays

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