gpt4 book ai didi

javascript - 使用干净的 url 将模型传递给 chaplinjs 中的其他 Controller

转载 作者:行者123 更新时间:2023-11-28 00:53:14 24 4
gpt4 key购买 nike

我正在使用 brunch-with-chaplinjs 样板和一些附加库(sinon、selenium、chai 和 mocha)。现在我想将模型从 View (确切地说是 Collection View )传递到另一个 Controller 进行编辑。

我可以这样做:

Chaplin.utils.redirectTo 'editaddress', model:@model

但这让我的网址变得困惑:

localhost:8080/editaddress?model=%5Bobject%20Object%5D

我似乎找不到任何可接受的方法来保持 URL 干净,并且仍然将整个模型传递给另一个 Controller ,而不需要从服务器重新获取模型。

最佳答案

通常你会使用卓别林的 composer ,但仅用于重用 View 。

你仍然可以通过堆栈来做到这一点。

application.coffee 中创建一个堆栈,您可以在更改 Controller 时存储项目。

# This is hidden from all other files so it is save, if you don't use any AMD,
# you should place this inside the application object.
stack = []

module.exports = class Application extends Chaplin.Application

### Your program here ###

start: ->

# Other code here

Mediator.setHandler 'push', @push
Mediator.setHandler 'pop', @pop

###
# Push to temporary storage stack.
###
push: (item)->
push item

###
# Pop form temporary storage stack.
###
pop: ->
return stack.pop()

现在您可以从代码中的任何位置推送到堆栈,如下所示:

Mediator.execute 'push', @model

要检索您可以使用:

Mediator.execute 'pop'

关于javascript - 使用干净的 url 将模型传递给 chaplinjs 中的其他 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26524760/

24 4 0
文章推荐: c++ - 使用具有生成器类型的 C++ 模板函数
文章推荐: javascript - IE 8 fireEvent 未指定错误
文章推荐: javascript - Backbone 模型: format current dateTime
文章推荐: javascript - 如何从 .php 检索数据并在 Cordova 混合应用程序中的