Last active
August 29, 2015 14:21
-
-
Save wmakeev/417518372fd10f5d0c64 to your computer and use it in GitHub Desktop.
Расширение объектной модели МойСклад
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var moysklad = require('moysklad-client'); | |
var client = moysklad.createClient(); | |
// Создаем пустой объект отгрузки | |
// использовать ключевое слово new не нужно | |
var demand = client.Demand({ | |
name: '10005' | |
}); | |
demand.TYPE_NAME // -> moysklad.demand | |
// сохраняем | |
demand.save(); | |
// или так | |
client.save(demand); | |
// Можем добавить метод для всех объектов указанного типа | |
client.CustomerOrder.methods({ | |
totalQuantity: function () { | |
return this.customerOrderPosition.reduce((total, pos) => { | |
return total + pos.quantity; | |
}, 0) | |
} | |
}) | |
// Затем получить заказ | |
var order = client.load('customerOrder', uuid); | |
// Метод totalQuantity доступен у всех заказов | |
var totalGoods = order.totalQuantity() // -> 15 | |
// Нельзя использовать instanceof .. | |
order instanceof client.Entity // -> false | |
order instanceof client.CustomerOrder // -> false | |
// .. вместо instanceof | |
order.instanceOf('entity'); // -> true | |
order.instanceOf('customerOrder'); // -> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment